/*
Copyright (c) 2024 Bytedance Ltd. and/or its affiliates
This file is part of ByteQC.

ByteQC includes code adapted from PySCF (https://github.com/pyscf/pyscf)
and GPU4PySCF (https://github.com/bytedance/gpu4pyscf),
which are licensed under the Apache License 2.0.
The original copyright:
    Copyright 2014-2020 The GPU4PySCF/PySCF Developers. All Rights Reserved.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

template <bool T>
__global__ static void GINTfill_int2e_kernel0022(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c0px;
        double g_2 = c0px * c0px + b01;
        double g_3 = c0px + xkxl;
        double g_4 = c0px * (c0px + xkxl) + b01;
        double g_5 = c0px * (2 * b01 + g_2) + xkxl * g_2;
        double g_6 = xkxl * (xkxl + c0px) + xkxl * c0px + c0px * c0px + b01;
        double g_7 = xkxl * (xkxl * c0px + c0px * c0px + b01) + xkxl * g_2 +
                     c0px * g_2 + 2 * b01 * c0px;
        double g_8 = xkxl * (xkxl * g_2 + c0px * g_2 + 2 * b01 * c0px) +
                     xkxl * (c0px * g_2 + 2 * b01 * c0px) +
                     c0px * (c0px * g_2 + 2 * b01 * c0px) + 3 * b01 * g_2;
        double g_9 = 1;
        double g_10 = c0py;
        double g_11 = c0py * c0py + b01;
        double g_12 = c0py + ykyl;
        double g_13 = c0py * (c0py + ykyl) + b01;
        double g_14 = c0py * (2 * b01 + g_11) + ykyl * g_11;
        double g_15 = ykyl * (ykyl + c0py) + ykyl * c0py + c0py * c0py + b01;
        double g_16 = ykyl * (ykyl * c0py + c0py * c0py + b01) + ykyl * g_11 +
                      c0py * g_11 + 2 * b01 * c0py;
        double g_17 = ykyl * (ykyl * g_11 + c0py * g_11 + 2 * b01 * c0py) +
                      ykyl * (c0py * g_11 + 2 * b01 * c0py) +
                      c0py * (c0py * g_11 + 2 * b01 * c0py) + 3 * b01 * g_11;
        double g_18 = weight0 * fac;
        double g_19 = c0pz * g_18;
        double g_20 = b01 * g_18 + c0pz * g_19;
        double g_21 = g_18 * (c0pz + zkzl);
        double g_22 = b01 * g_18 + c0pz * g_19 + zkzl * g_19;
        double g_23 = 2 * b01 * g_19 + c0pz * g_20 + zkzl * g_20;
        double g_24 = zkzl * (zkzl * g_18 + c0pz * g_18) + zkzl * g_19 +
                      c0pz * g_19 + b01 * g_18;
        double g_25 = zkzl * (zkzl * g_19 + c0pz * g_19 + b01 * g_18) +
                      zkzl * g_20 + c0pz * g_20 + 2 * b01 * g_19;
        double g_26 = zkzl * (zkzl * g_20 + c0pz * g_20 + 2 * b01 * g_19) +
                      zkzl * (c0pz * g_20 + 2 * b01 * g_19) +
                      c0pz * (c0pz * g_20 + 2 * b01 * g_19) + 3 * b01 * g_20;
        gout0 += g_8 * g_9 * g_18;
        gout1 += g_7 * g_10 * g_18;
        gout2 += g_7 * g_9 * g_19;
        gout3 += g_6 * g_11 * g_18;
        gout4 += g_6 * g_10 * g_19;
        gout5 += g_6 * g_9 * g_20;
        gout6 += g_5 * g_12 * g_18;
        gout7 += g_4 * g_13 * g_18;
        gout8 += g_4 * g_12 * g_19;
        gout9 += g_3 * g_14 * g_18;
        gout10 += g_3 * g_13 * g_19;
        gout11 += g_3 * g_12 * g_20;
        gout12 += g_5 * g_9 * g_21;
        gout13 += g_4 * g_10 * g_21;
        gout14 += g_4 * g_9 * g_22;
        gout15 += g_3 * g_11 * g_21;
        gout16 += g_3 * g_10 * g_22;
        gout17 += g_3 * g_9 * g_23;
        gout18 += g_2 * g_15 * g_18;
        gout19 += g_1 * g_16 * g_18;
        gout20 += g_1 * g_15 * g_19;
        gout21 += g_0 * g_17 * g_18;
        gout22 += g_0 * g_16 * g_19;
        gout23 += g_0 * g_15 * g_20;
        gout24 += g_2 * g_12 * g_21;
        gout25 += g_1 * g_13 * g_21;
        gout26 += g_1 * g_12 * g_22;
        gout27 += g_0 * g_14 * g_21;
        gout28 += g_0 * g_13 * g_22;
        gout29 += g_0 * g_12 * g_23;
        gout30 += g_2 * g_9 * g_24;
        gout31 += g_1 * g_10 * g_24;
        gout32 += g_1 * g_9 * g_25;
        gout33 += g_0 * g_11 * g_24;
        gout34 += g_0 * g_10 * g_25;
        gout35 += g_0 * g_9 * g_26;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * kstride, gout1);
    atomicAdd(peri + 2 * kstride, gout2);
    atomicAdd(peri + 3 * kstride, gout3);
    atomicAdd(peri + 4 * kstride, gout4);
    atomicAdd(peri + 5 * kstride, gout5);
    atomicAdd(peri + 1 * lstride, gout6);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout7);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout8);
    atomicAdd(peri + 3 * kstride + 1 * lstride, gout9);
    atomicAdd(peri + 4 * kstride + 1 * lstride, gout10);
    atomicAdd(peri + 5 * kstride + 1 * lstride, gout11);
    atomicAdd(peri + 2 * lstride, gout12);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout13);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout14);
    atomicAdd(peri + 3 * kstride + 2 * lstride, gout15);
    atomicAdd(peri + 4 * kstride + 2 * lstride, gout16);
    atomicAdd(peri + 5 * kstride + 2 * lstride, gout17);
    atomicAdd(peri + 3 * lstride, gout18);
    atomicAdd(peri + 1 * kstride + 3 * lstride, gout19);
    atomicAdd(peri + 2 * kstride + 3 * lstride, gout20);
    atomicAdd(peri + 3 * kstride + 3 * lstride, gout21);
    atomicAdd(peri + 4 * kstride + 3 * lstride, gout22);
    atomicAdd(peri + 5 * kstride + 3 * lstride, gout23);
    atomicAdd(peri + 4 * lstride, gout24);
    atomicAdd(peri + 1 * kstride + 4 * lstride, gout25);
    atomicAdd(peri + 2 * kstride + 4 * lstride, gout26);
    atomicAdd(peri + 3 * kstride + 4 * lstride, gout27);
    atomicAdd(peri + 4 * kstride + 4 * lstride, gout28);
    atomicAdd(peri + 5 * kstride + 4 * lstride, gout29);
    atomicAdd(peri + 5 * lstride, gout30);
    atomicAdd(peri + 1 * kstride + 5 * lstride, gout31);
    atomicAdd(peri + 2 * kstride + 5 * lstride, gout32);
    atomicAdd(peri + 3 * kstride + 5 * lstride, gout33);
    atomicAdd(peri + 4 * kstride + 5 * lstride, gout34);
    atomicAdd(peri + 5 * kstride + 5 * lstride, gout35);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel0031(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c0px;
        double g_2 = c0px * c0px + b01;
        double g_3 = c0px * (2 * b01 + g_2);
        double g_4 = c0px + xkxl;
        double g_5 = c0px * (c0px + xkxl) + b01;
        double g_6 = c0px * (2 * b01 + g_2) + xkxl * g_2;
        double g_7 = 3 * b01 * g_2 + c0px * g_3 + xkxl * g_3;
        double g_8 = 1;
        double g_9 = c0py;
        double g_10 = c0py * c0py + b01;
        double g_11 = c0py * (2 * b01 + g_10);
        double g_12 = c0py + ykyl;
        double g_13 = c0py * (c0py + ykyl) + b01;
        double g_14 = c0py * (2 * b01 + g_10) + ykyl * g_10;
        double g_15 = 3 * b01 * g_10 + c0py * g_11 + ykyl * g_11;
        double g_16 = weight0 * fac;
        double g_17 = c0pz * g_16;
        double g_18 = b01 * g_16 + c0pz * g_17;
        double g_19 = 2 * b01 * g_17 + c0pz * g_18;
        double g_20 = g_16 * (c0pz + zkzl);
        double g_21 = b01 * g_16 + c0pz * g_17 + zkzl * g_17;
        double g_22 = 2 * b01 * g_17 + c0pz * g_18 + zkzl * g_18;
        double g_23 = 3 * b01 * g_18 + c0pz * g_19 + zkzl * g_19;
        gout0 += g_7 * g_8 * g_16;
        gout1 += g_6 * g_9 * g_16;
        gout2 += g_6 * g_8 * g_17;
        gout3 += g_5 * g_10 * g_16;
        gout4 += g_5 * g_9 * g_17;
        gout5 += g_5 * g_8 * g_18;
        gout6 += g_4 * g_11 * g_16;
        gout7 += g_4 * g_10 * g_17;
        gout8 += g_4 * g_9 * g_18;
        gout9 += g_4 * g_8 * g_19;
        gout10 += g_3 * g_12 * g_16;
        gout11 += g_2 * g_13 * g_16;
        gout12 += g_2 * g_12 * g_17;
        gout13 += g_1 * g_14 * g_16;
        gout14 += g_1 * g_13 * g_17;
        gout15 += g_1 * g_12 * g_18;
        gout16 += g_0 * g_15 * g_16;
        gout17 += g_0 * g_14 * g_17;
        gout18 += g_0 * g_13 * g_18;
        gout19 += g_0 * g_12 * g_19;
        gout20 += g_3 * g_8 * g_20;
        gout21 += g_2 * g_9 * g_20;
        gout22 += g_2 * g_8 * g_21;
        gout23 += g_1 * g_10 * g_20;
        gout24 += g_1 * g_9 * g_21;
        gout25 += g_1 * g_8 * g_22;
        gout26 += g_0 * g_11 * g_20;
        gout27 += g_0 * g_10 * g_21;
        gout28 += g_0 * g_9 * g_22;
        gout29 += g_0 * g_8 * g_23;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * kstride, gout1);
    atomicAdd(peri + 2 * kstride, gout2);
    atomicAdd(peri + 3 * kstride, gout3);
    atomicAdd(peri + 4 * kstride, gout4);
    atomicAdd(peri + 5 * kstride, gout5);
    atomicAdd(peri + 6 * kstride, gout6);
    atomicAdd(peri + 7 * kstride, gout7);
    atomicAdd(peri + 8 * kstride, gout8);
    atomicAdd(peri + 9 * kstride, gout9);
    atomicAdd(peri + 1 * lstride, gout10);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout11);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout12);
    atomicAdd(peri + 3 * kstride + 1 * lstride, gout13);
    atomicAdd(peri + 4 * kstride + 1 * lstride, gout14);
    atomicAdd(peri + 5 * kstride + 1 * lstride, gout15);
    atomicAdd(peri + 6 * kstride + 1 * lstride, gout16);
    atomicAdd(peri + 7 * kstride + 1 * lstride, gout17);
    atomicAdd(peri + 8 * kstride + 1 * lstride, gout18);
    atomicAdd(peri + 9 * kstride + 1 * lstride, gout19);
    atomicAdd(peri + 2 * lstride, gout20);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout21);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout22);
    atomicAdd(peri + 3 * kstride + 2 * lstride, gout23);
    atomicAdd(peri + 4 * kstride + 2 * lstride, gout24);
    atomicAdd(peri + 5 * kstride + 2 * lstride, gout25);
    atomicAdd(peri + 6 * kstride + 2 * lstride, gout26);
    atomicAdd(peri + 7 * kstride + 2 * lstride, gout27);
    atomicAdd(peri + 8 * kstride + 2 * lstride, gout28);
    atomicAdd(peri + 9 * kstride + 2 * lstride, gout29);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel0032(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c0px;
        double g_2 = c0px * c0px + b01;
        double g_3 = c0px * (2 * b01 + g_2);
        double g_4 = c0px + xkxl;
        double g_5 = c0px * (c0px + xkxl) + b01;
        double g_6 = c0px * (2 * b01 + g_2) + xkxl * g_2;
        double g_7 = 3 * b01 * g_2 + c0px * g_3 + xkxl * g_3;
        double g_8 = xkxl * (xkxl + c0px) + xkxl * c0px + c0px * c0px + b01;
        double g_9 = xkxl * (xkxl * c0px + c0px * c0px + b01) + xkxl * g_2 +
                     c0px * g_2 + 2 * b01 * c0px;
        double g_10 = xkxl * (xkxl * g_2 + c0px * g_2 + 2 * b01 * c0px) +
                      xkxl * g_3 + c0px * g_3 + 3 * b01 * g_2;
        double g_11 = xkxl * (xkxl * g_3 + c0px * g_3 + 3 * b01 * g_2) +
                      xkxl * (c0px * g_3 + 3 * b01 * g_2) +
                      c0px * (c0px * g_3 + 3 * b01 * g_2) + 4 * b01 * g_3;
        double g_12 = 1;
        double g_13 = c0py;
        double g_14 = c0py * c0py + b01;
        double g_15 = c0py * (2 * b01 + g_14);
        double g_16 = c0py + ykyl;
        double g_17 = c0py * (c0py + ykyl) + b01;
        double g_18 = c0py * (2 * b01 + g_14) + ykyl * g_14;
        double g_19 = 3 * b01 * g_14 + c0py * g_15 + ykyl * g_15;
        double g_20 = ykyl * (ykyl + c0py) + ykyl * c0py + c0py * c0py + b01;
        double g_21 = ykyl * (ykyl * c0py + c0py * c0py + b01) + ykyl * g_14 +
                      c0py * g_14 + 2 * b01 * c0py;
        double g_22 = ykyl * (ykyl * g_14 + c0py * g_14 + 2 * b01 * c0py) +
                      ykyl * g_15 + c0py * g_15 + 3 * b01 * g_14;
        double g_23 = ykyl * (ykyl * g_15 + c0py * g_15 + 3 * b01 * g_14) +
                      ykyl * (c0py * g_15 + 3 * b01 * g_14) +
                      c0py * (c0py * g_15 + 3 * b01 * g_14) + 4 * b01 * g_15;
        double g_24 = weight0 * fac;
        double g_25 = c0pz * g_24;
        double g_26 = b01 * g_24 + c0pz * g_25;
        double g_27 = 2 * b01 * g_25 + c0pz * g_26;
        double g_28 = g_24 * (c0pz + zkzl);
        double g_29 = b01 * g_24 + c0pz * g_25 + zkzl * g_25;
        double g_30 = 2 * b01 * g_25 + c0pz * g_26 + zkzl * g_26;
        double g_31 = 3 * b01 * g_26 + c0pz * g_27 + zkzl * g_27;
        double g_32 = zkzl * (zkzl * g_24 + c0pz * g_24) + zkzl * g_25 +
                      c0pz * g_25 + b01 * g_24;
        double g_33 = zkzl * (zkzl * g_25 + c0pz * g_25 + b01 * g_24) +
                      zkzl * g_26 + c0pz * g_26 + 2 * b01 * g_25;
        double g_34 = zkzl * (zkzl * g_26 + c0pz * g_26 + 2 * b01 * g_25) +
                      zkzl * g_27 + c0pz * g_27 + 3 * b01 * g_26;
        double g_35 = zkzl * (zkzl * g_27 + c0pz * g_27 + 3 * b01 * g_26) +
                      zkzl * (c0pz * g_27 + 3 * b01 * g_26) +
                      c0pz * (c0pz * g_27 + 3 * b01 * g_26) + 4 * b01 * g_27;
        gout0 += g_11 * g_12 * g_24;
        gout1 += g_10 * g_13 * g_24;
        gout2 += g_10 * g_12 * g_25;
        gout3 += g_9 * g_14 * g_24;
        gout4 += g_9 * g_13 * g_25;
        gout5 += g_9 * g_12 * g_26;
        gout6 += g_8 * g_15 * g_24;
        gout7 += g_8 * g_14 * g_25;
        gout8 += g_8 * g_13 * g_26;
        gout9 += g_8 * g_12 * g_27;
        gout10 += g_7 * g_16 * g_24;
        gout11 += g_6 * g_17 * g_24;
        gout12 += g_6 * g_16 * g_25;
        gout13 += g_5 * g_18 * g_24;
        gout14 += g_5 * g_17 * g_25;
        gout15 += g_5 * g_16 * g_26;
        gout16 += g_4 * g_19 * g_24;
        gout17 += g_4 * g_18 * g_25;
        gout18 += g_4 * g_17 * g_26;
        gout19 += g_4 * g_16 * g_27;
        gout20 += g_7 * g_12 * g_28;
        gout21 += g_6 * g_13 * g_28;
        gout22 += g_6 * g_12 * g_29;
        gout23 += g_5 * g_14 * g_28;
        gout24 += g_5 * g_13 * g_29;
        gout25 += g_5 * g_12 * g_30;
        gout26 += g_4 * g_15 * g_28;
        gout27 += g_4 * g_14 * g_29;
        gout28 += g_4 * g_13 * g_30;
        gout29 += g_4 * g_12 * g_31;
        gout30 += g_3 * g_20 * g_24;
        gout31 += g_2 * g_21 * g_24;
        gout32 += g_2 * g_20 * g_25;
        gout33 += g_1 * g_22 * g_24;
        gout34 += g_1 * g_21 * g_25;
        gout35 += g_1 * g_20 * g_26;
        gout36 += g_0 * g_23 * g_24;
        gout37 += g_0 * g_22 * g_25;
        gout38 += g_0 * g_21 * g_26;
        gout39 += g_0 * g_20 * g_27;
        gout40 += g_3 * g_16 * g_28;
        gout41 += g_2 * g_17 * g_28;
        gout42 += g_2 * g_16 * g_29;
        gout43 += g_1 * g_18 * g_28;
        gout44 += g_1 * g_17 * g_29;
        gout45 += g_1 * g_16 * g_30;
        gout46 += g_0 * g_19 * g_28;
        gout47 += g_0 * g_18 * g_29;
        gout48 += g_0 * g_17 * g_30;
        gout49 += g_0 * g_16 * g_31;
        gout50 += g_3 * g_12 * g_32;
        gout51 += g_2 * g_13 * g_32;
        gout52 += g_2 * g_12 * g_33;
        gout53 += g_1 * g_14 * g_32;
        gout54 += g_1 * g_13 * g_33;
        gout55 += g_1 * g_12 * g_34;
        gout56 += g_0 * g_15 * g_32;
        gout57 += g_0 * g_14 * g_33;
        gout58 += g_0 * g_13 * g_34;
        gout59 += g_0 * g_12 * g_35;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * kstride, gout1);
    atomicAdd(peri + 2 * kstride, gout2);
    atomicAdd(peri + 3 * kstride, gout3);
    atomicAdd(peri + 4 * kstride, gout4);
    atomicAdd(peri + 5 * kstride, gout5);
    atomicAdd(peri + 6 * kstride, gout6);
    atomicAdd(peri + 7 * kstride, gout7);
    atomicAdd(peri + 8 * kstride, gout8);
    atomicAdd(peri + 9 * kstride, gout9);
    atomicAdd(peri + 1 * lstride, gout10);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout11);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout12);
    atomicAdd(peri + 3 * kstride + 1 * lstride, gout13);
    atomicAdd(peri + 4 * kstride + 1 * lstride, gout14);
    atomicAdd(peri + 5 * kstride + 1 * lstride, gout15);
    atomicAdd(peri + 6 * kstride + 1 * lstride, gout16);
    atomicAdd(peri + 7 * kstride + 1 * lstride, gout17);
    atomicAdd(peri + 8 * kstride + 1 * lstride, gout18);
    atomicAdd(peri + 9 * kstride + 1 * lstride, gout19);
    atomicAdd(peri + 2 * lstride, gout20);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout21);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout22);
    atomicAdd(peri + 3 * kstride + 2 * lstride, gout23);
    atomicAdd(peri + 4 * kstride + 2 * lstride, gout24);
    atomicAdd(peri + 5 * kstride + 2 * lstride, gout25);
    atomicAdd(peri + 6 * kstride + 2 * lstride, gout26);
    atomicAdd(peri + 7 * kstride + 2 * lstride, gout27);
    atomicAdd(peri + 8 * kstride + 2 * lstride, gout28);
    atomicAdd(peri + 9 * kstride + 2 * lstride, gout29);
    atomicAdd(peri + 3 * lstride, gout30);
    atomicAdd(peri + 1 * kstride + 3 * lstride, gout31);
    atomicAdd(peri + 2 * kstride + 3 * lstride, gout32);
    atomicAdd(peri + 3 * kstride + 3 * lstride, gout33);
    atomicAdd(peri + 4 * kstride + 3 * lstride, gout34);
    atomicAdd(peri + 5 * kstride + 3 * lstride, gout35);
    atomicAdd(peri + 6 * kstride + 3 * lstride, gout36);
    atomicAdd(peri + 7 * kstride + 3 * lstride, gout37);
    atomicAdd(peri + 8 * kstride + 3 * lstride, gout38);
    atomicAdd(peri + 9 * kstride + 3 * lstride, gout39);
    atomicAdd(peri + 4 * lstride, gout40);
    atomicAdd(peri + 1 * kstride + 4 * lstride, gout41);
    atomicAdd(peri + 2 * kstride + 4 * lstride, gout42);
    atomicAdd(peri + 3 * kstride + 4 * lstride, gout43);
    atomicAdd(peri + 4 * kstride + 4 * lstride, gout44);
    atomicAdd(peri + 5 * kstride + 4 * lstride, gout45);
    atomicAdd(peri + 6 * kstride + 4 * lstride, gout46);
    atomicAdd(peri + 7 * kstride + 4 * lstride, gout47);
    atomicAdd(peri + 8 * kstride + 4 * lstride, gout48);
    atomicAdd(peri + 9 * kstride + 4 * lstride, gout49);
    atomicAdd(peri + 5 * lstride, gout50);
    atomicAdd(peri + 1 * kstride + 5 * lstride, gout51);
    atomicAdd(peri + 2 * kstride + 5 * lstride, gout52);
    atomicAdd(peri + 3 * kstride + 5 * lstride, gout53);
    atomicAdd(peri + 4 * kstride + 5 * lstride, gout54);
    atomicAdd(peri + 5 * kstride + 5 * lstride, gout55);
    atomicAdd(peri + 6 * kstride + 5 * lstride, gout56);
    atomicAdd(peri + 7 * kstride + 5 * lstride, gout57);
    atomicAdd(peri + 8 * kstride + 5 * lstride, gout58);
    atomicAdd(peri + 9 * kstride + 5 * lstride, gout59);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel1021(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c0px;
        double g_3 = c0px * c00x + b00;
        double g_4 = c0px * c0px + b01;
        double g_5 = b00 * c0px + b01 * c00x + c0px * g_3;
        double g_6 = c0px + xkxl;
        double g_7 = c00x * (c0px + xkxl) + b00;
        double g_8 = c0px * (c0px + xkxl) + b01;
        double g_9 = b00 * c0px + b01 * c00x + c0px * g_3 + xkxl * g_3;
        double g_10 = c0px * (2 * b01 + g_4) + xkxl * g_4;
        double g_11 = 2 * b01 * g_3 + b00 * g_4 + c0px * g_5 + xkxl * g_5;
        double g_12 = 1;
        double g_13 = c00y;
        double g_14 = c0py;
        double g_15 = c0py * c00y + b00;
        double g_16 = c0py * c0py + b01;
        double g_17 = b00 * c0py + b01 * c00y + c0py * g_15;
        double g_18 = c0py + ykyl;
        double g_19 = c00y * (c0py + ykyl) + b00;
        double g_20 = c0py * (c0py + ykyl) + b01;
        double g_21 = b00 * c0py + b01 * c00y + c0py * g_15 + ykyl * g_15;
        double g_22 = c0py * (2 * b01 + g_16) + ykyl * g_16;
        double g_23 = 2 * b01 * g_15 + b00 * g_16 + c0py * g_17 + ykyl * g_17;
        double g_24 = weight0 * fac;
        double g_25 = c00z * g_24;
        double g_26 = c0pz * g_24;
        double g_27 = b00 * g_24 + c0pz * g_25;
        double g_28 = b01 * g_24 + c0pz * g_26;
        double g_29 = b00 * g_26 + b01 * g_25 + c0pz * g_27;
        double g_30 = g_24 * (c0pz + zkzl);
        double g_31 = b00 * g_24 + c0pz * g_25 + zkzl * g_25;
        double g_32 = b01 * g_24 + c0pz * g_26 + zkzl * g_26;
        double g_33 = b00 * g_26 + b01 * g_25 + c0pz * g_27 + zkzl * g_27;
        double g_34 = 2 * b01 * g_26 + c0pz * g_28 + zkzl * g_28;
        double g_35 = 2 * b01 * g_27 + b00 * g_28 + c0pz * g_29 + zkzl * g_29;
        gout0 += g_11 * g_12 * g_24;
        gout1 += g_10 * g_13 * g_24;
        gout2 += g_10 * g_12 * g_25;
        gout3 += g_9 * g_14 * g_24;
        gout4 += g_8 * g_15 * g_24;
        gout5 += g_8 * g_14 * g_25;
        gout6 += g_9 * g_12 * g_26;
        gout7 += g_8 * g_13 * g_26;
        gout8 += g_8 * g_12 * g_27;
        gout9 += g_7 * g_16 * g_24;
        gout10 += g_6 * g_17 * g_24;
        gout11 += g_6 * g_16 * g_25;
        gout12 += g_7 * g_14 * g_26;
        gout13 += g_6 * g_15 * g_26;
        gout14 += g_6 * g_14 * g_27;
        gout15 += g_7 * g_12 * g_28;
        gout16 += g_6 * g_13 * g_28;
        gout17 += g_6 * g_12 * g_29;
        gout18 += g_5 * g_18 * g_24;
        gout19 += g_4 * g_19 * g_24;
        gout20 += g_4 * g_18 * g_25;
        gout21 += g_3 * g_20 * g_24;
        gout22 += g_2 * g_21 * g_24;
        gout23 += g_2 * g_20 * g_25;
        gout24 += g_3 * g_18 * g_26;
        gout25 += g_2 * g_19 * g_26;
        gout26 += g_2 * g_18 * g_27;
        gout27 += g_1 * g_22 * g_24;
        gout28 += g_0 * g_23 * g_24;
        gout29 += g_0 * g_22 * g_25;
        gout30 += g_1 * g_20 * g_26;
        gout31 += g_0 * g_21 * g_26;
        gout32 += g_0 * g_20 * g_27;
        gout33 += g_1 * g_18 * g_28;
        gout34 += g_0 * g_19 * g_28;
        gout35 += g_0 * g_18 * g_29;
        gout36 += g_5 * g_12 * g_30;
        gout37 += g_4 * g_13 * g_30;
        gout38 += g_4 * g_12 * g_31;
        gout39 += g_3 * g_14 * g_30;
        gout40 += g_2 * g_15 * g_30;
        gout41 += g_2 * g_14 * g_31;
        gout42 += g_3 * g_12 * g_32;
        gout43 += g_2 * g_13 * g_32;
        gout44 += g_2 * g_12 * g_33;
        gout45 += g_1 * g_16 * g_30;
        gout46 += g_0 * g_17 * g_30;
        gout47 += g_0 * g_16 * g_31;
        gout48 += g_1 * g_14 * g_32;
        gout49 += g_0 * g_15 * g_32;
        gout50 += g_0 * g_14 * g_33;
        gout51 += g_1 * g_12 * g_34;
        gout52 += g_0 * g_13 * g_34;
        gout53 += g_0 * g_12 * g_35;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 1 * kstride, gout3);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout4);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout5);
    atomicAdd(peri + 2 * kstride, gout6);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout7);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout8);
    atomicAdd(peri + 3 * kstride, gout9);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout10);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout11);
    atomicAdd(peri + 4 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout14);
    atomicAdd(peri + 5 * kstride, gout15);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout16);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout17);
    atomicAdd(peri + 1 * lstride, gout18);
    atomicAdd(peri + 1 * istride + 1 * lstride, gout19);
    atomicAdd(peri + 2 * istride + 1 * lstride, gout20);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout21);
    atomicAdd(peri + 1 * istride + 1 * kstride + 1 * lstride, gout22);
    atomicAdd(peri + 2 * istride + 1 * kstride + 1 * lstride, gout23);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout24);
    atomicAdd(peri + 1 * istride + 2 * kstride + 1 * lstride, gout25);
    atomicAdd(peri + 2 * istride + 2 * kstride + 1 * lstride, gout26);
    atomicAdd(peri + 3 * kstride + 1 * lstride, gout27);
    atomicAdd(peri + 1 * istride + 3 * kstride + 1 * lstride, gout28);
    atomicAdd(peri + 2 * istride + 3 * kstride + 1 * lstride, gout29);
    atomicAdd(peri + 4 * kstride + 1 * lstride, gout30);
    atomicAdd(peri + 1 * istride + 4 * kstride + 1 * lstride, gout31);
    atomicAdd(peri + 2 * istride + 4 * kstride + 1 * lstride, gout32);
    atomicAdd(peri + 5 * kstride + 1 * lstride, gout33);
    atomicAdd(peri + 1 * istride + 5 * kstride + 1 * lstride, gout34);
    atomicAdd(peri + 2 * istride + 5 * kstride + 1 * lstride, gout35);
    atomicAdd(peri + 2 * lstride, gout36);
    atomicAdd(peri + 1 * istride + 2 * lstride, gout37);
    atomicAdd(peri + 2 * istride + 2 * lstride, gout38);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout39);
    atomicAdd(peri + 1 * istride + 1 * kstride + 2 * lstride, gout40);
    atomicAdd(peri + 2 * istride + 1 * kstride + 2 * lstride, gout41);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout42);
    atomicAdd(peri + 1 * istride + 2 * kstride + 2 * lstride, gout43);
    atomicAdd(peri + 2 * istride + 2 * kstride + 2 * lstride, gout44);
    atomicAdd(peri + 3 * kstride + 2 * lstride, gout45);
    atomicAdd(peri + 1 * istride + 3 * kstride + 2 * lstride, gout46);
    atomicAdd(peri + 2 * istride + 3 * kstride + 2 * lstride, gout47);
    atomicAdd(peri + 4 * kstride + 2 * lstride, gout48);
    atomicAdd(peri + 1 * istride + 4 * kstride + 2 * lstride, gout49);
    atomicAdd(peri + 2 * istride + 4 * kstride + 2 * lstride, gout50);
    atomicAdd(peri + 5 * kstride + 2 * lstride, gout51);
    atomicAdd(peri + 1 * istride + 5 * kstride + 2 * lstride, gout52);
    atomicAdd(peri + 2 * istride + 5 * kstride + 2 * lstride, gout53);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel1022(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c0px;
        double g_3 = c0px * c00x + b00;
        double g_4 = c0px * c0px + b01;
        double g_5 = b00 * c0px + b01 * c00x + c0px * g_3;
        double g_6 = c0px + xkxl;
        double g_7 = c00x * (c0px + xkxl) + b00;
        double g_8 = c0px * (c0px + xkxl) + b01;
        double g_9 = b00 * c0px + b01 * c00x + c0px * g_3 + xkxl * g_3;
        double g_10 = c0px * (2 * b01 + g_4) + xkxl * g_4;
        double g_11 = 2 * b01 * g_3 + b00 * g_4 + c0px * g_5 + xkxl * g_5;
        double g_12 = xkxl * (xkxl + c0px) + xkxl * c0px + c0px * c0px + b01;
        double g_13 = xkxl * (xkxl * c00x + c0px * c00x + b00) + xkxl * g_3 +
                      c0px * g_3 + b01 * c00x + b00 * c0px;
        double g_14 = xkxl * (xkxl * c0px + c0px * c0px + b01) + xkxl * g_4 +
                      c0px * g_4 + 2 * b01 * c0px;
        double g_15 =
            xkxl * (xkxl * g_3 + c0px * g_3 + b01 * c00x + b00 * c0px) +
            xkxl * g_5 + c0px * g_5 + 2 * b01 * g_3 + b00 * g_4;
        double g_16 = xkxl * (xkxl * g_4 + c0px * g_4 + 2 * b01 * c0px) +
                      xkxl * (c0px * g_4 + 2 * b01 * c0px) +
                      c0px * (c0px * g_4 + 2 * b01 * c0px) + 3 * b01 * g_4;
        double g_17 =
            xkxl * (xkxl * g_5 + c0px * g_5 + 2 * b01 * g_3 + b00 * g_4) +
            xkxl * (c0px * g_5 + 2 * b01 * g_3 + b00 * g_4) +
            c0px * (c0px * g_5 + 2 * b01 * g_3 + b00 * g_4) + 3 * b01 * g_5 +
            b00 * (c0px * g_4 + 2 * b01 * c0px);
        double g_18 = 1;
        double g_19 = c00y;
        double g_20 = c0py;
        double g_21 = c0py * c00y + b00;
        double g_22 = c0py * c0py + b01;
        double g_23 = b00 * c0py + b01 * c00y + c0py * g_21;
        double g_24 = c0py + ykyl;
        double g_25 = c00y * (c0py + ykyl) + b00;
        double g_26 = c0py * (c0py + ykyl) + b01;
        double g_27 = b00 * c0py + b01 * c00y + c0py * g_21 + ykyl * g_21;
        double g_28 = c0py * (2 * b01 + g_22) + ykyl * g_22;
        double g_29 = 2 * b01 * g_21 + b00 * g_22 + c0py * g_23 + ykyl * g_23;
        double g_30 = ykyl * (ykyl + c0py) + ykyl * c0py + c0py * c0py + b01;
        double g_31 = ykyl * (ykyl * c00y + c0py * c00y + b00) + ykyl * g_21 +
                      c0py * g_21 + b01 * c00y + b00 * c0py;
        double g_32 = ykyl * (ykyl * c0py + c0py * c0py + b01) + ykyl * g_22 +
                      c0py * g_22 + 2 * b01 * c0py;
        double g_33 =
            ykyl * (ykyl * g_21 + c0py * g_21 + b01 * c00y + b00 * c0py) +
            ykyl * g_23 + c0py * g_23 + 2 * b01 * g_21 + b00 * g_22;
        double g_34 = ykyl * (ykyl * g_22 + c0py * g_22 + 2 * b01 * c0py) +
                      ykyl * (c0py * g_22 + 2 * b01 * c0py) +
                      c0py * (c0py * g_22 + 2 * b01 * c0py) + 3 * b01 * g_22;
        double g_35 =
            ykyl * (ykyl * g_23 + c0py * g_23 + 2 * b01 * g_21 + b00 * g_22) +
            ykyl * (c0py * g_23 + 2 * b01 * g_21 + b00 * g_22) +
            c0py * (c0py * g_23 + 2 * b01 * g_21 + b00 * g_22) +
            3 * b01 * g_23 + b00 * (c0py * g_22 + 2 * b01 * c0py);
        double g_36 = weight0 * fac;
        double g_37 = c00z * g_36;
        double g_38 = c0pz * g_36;
        double g_39 = b00 * g_36 + c0pz * g_37;
        double g_40 = b01 * g_36 + c0pz * g_38;
        double g_41 = b00 * g_38 + b01 * g_37 + c0pz * g_39;
        double g_42 = g_36 * (c0pz + zkzl);
        double g_43 = b00 * g_36 + c0pz * g_37 + zkzl * g_37;
        double g_44 = b01 * g_36 + c0pz * g_38 + zkzl * g_38;
        double g_45 = b00 * g_38 + b01 * g_37 + c0pz * g_39 + zkzl * g_39;
        double g_46 = 2 * b01 * g_38 + c0pz * g_40 + zkzl * g_40;
        double g_47 = 2 * b01 * g_39 + b00 * g_40 + c0pz * g_41 + zkzl * g_41;
        double g_48 = zkzl * (zkzl * g_36 + c0pz * g_36) + zkzl * g_38 +
                      c0pz * g_38 + b01 * g_36;
        double g_49 = zkzl * (zkzl * g_37 + c0pz * g_37 + b00 * g_36) +
                      zkzl * g_39 + c0pz * g_39 + b01 * g_37 + b00 * g_38;
        double g_50 = zkzl * (zkzl * g_38 + c0pz * g_38 + b01 * g_36) +
                      zkzl * g_40 + c0pz * g_40 + 2 * b01 * g_38;
        double g_51 =
            zkzl * (zkzl * g_39 + c0pz * g_39 + b01 * g_37 + b00 * g_38) +
            zkzl * g_41 + c0pz * g_41 + 2 * b01 * g_39 + b00 * g_40;
        double g_52 = zkzl * (zkzl * g_40 + c0pz * g_40 + 2 * b01 * g_38) +
                      zkzl * (c0pz * g_40 + 2 * b01 * g_38) +
                      c0pz * (c0pz * g_40 + 2 * b01 * g_38) + 3 * b01 * g_40;
        double g_53 =
            zkzl * (zkzl * g_41 + c0pz * g_41 + 2 * b01 * g_39 + b00 * g_40) +
            zkzl * (c0pz * g_41 + 2 * b01 * g_39 + b00 * g_40) +
            c0pz * (c0pz * g_41 + 2 * b01 * g_39 + b00 * g_40) +
            3 * b01 * g_41 + b00 * (c0pz * g_40 + 2 * b01 * g_38);
        gout0 += g_17 * g_18 * g_36;
        gout1 += g_16 * g_19 * g_36;
        gout2 += g_16 * g_18 * g_37;
        gout3 += g_15 * g_20 * g_36;
        gout4 += g_14 * g_21 * g_36;
        gout5 += g_14 * g_20 * g_37;
        gout6 += g_15 * g_18 * g_38;
        gout7 += g_14 * g_19 * g_38;
        gout8 += g_14 * g_18 * g_39;
        gout9 += g_13 * g_22 * g_36;
        gout10 += g_12 * g_23 * g_36;
        gout11 += g_12 * g_22 * g_37;
        gout12 += g_13 * g_20 * g_38;
        gout13 += g_12 * g_21 * g_38;
        gout14 += g_12 * g_20 * g_39;
        gout15 += g_13 * g_18 * g_40;
        gout16 += g_12 * g_19 * g_40;
        gout17 += g_12 * g_18 * g_41;
        gout18 += g_11 * g_24 * g_36;
        gout19 += g_10 * g_25 * g_36;
        gout20 += g_10 * g_24 * g_37;
        gout21 += g_9 * g_26 * g_36;
        gout22 += g_8 * g_27 * g_36;
        gout23 += g_8 * g_26 * g_37;
        gout24 += g_9 * g_24 * g_38;
        gout25 += g_8 * g_25 * g_38;
        gout26 += g_8 * g_24 * g_39;
        gout27 += g_7 * g_28 * g_36;
        gout28 += g_6 * g_29 * g_36;
        gout29 += g_6 * g_28 * g_37;
        gout30 += g_7 * g_26 * g_38;
        gout31 += g_6 * g_27 * g_38;
        gout32 += g_6 * g_26 * g_39;
        gout33 += g_7 * g_24 * g_40;
        gout34 += g_6 * g_25 * g_40;
        gout35 += g_6 * g_24 * g_41;
        gout36 += g_11 * g_18 * g_42;
        gout37 += g_10 * g_19 * g_42;
        gout38 += g_10 * g_18 * g_43;
        gout39 += g_9 * g_20 * g_42;
        gout40 += g_8 * g_21 * g_42;
        gout41 += g_8 * g_20 * g_43;
        gout42 += g_9 * g_18 * g_44;
        gout43 += g_8 * g_19 * g_44;
        gout44 += g_8 * g_18 * g_45;
        gout45 += g_7 * g_22 * g_42;
        gout46 += g_6 * g_23 * g_42;
        gout47 += g_6 * g_22 * g_43;
        gout48 += g_7 * g_20 * g_44;
        gout49 += g_6 * g_21 * g_44;
        gout50 += g_6 * g_20 * g_45;
        gout51 += g_7 * g_18 * g_46;
        gout52 += g_6 * g_19 * g_46;
        gout53 += g_6 * g_18 * g_47;
        gout54 += g_5 * g_30 * g_36;
        gout55 += g_4 * g_31 * g_36;
        gout56 += g_4 * g_30 * g_37;
        gout57 += g_3 * g_32 * g_36;
        gout58 += g_2 * g_33 * g_36;
        gout59 += g_2 * g_32 * g_37;
        gout60 += g_3 * g_30 * g_38;
        gout61 += g_2 * g_31 * g_38;
        gout62 += g_2 * g_30 * g_39;
        gout63 += g_1 * g_34 * g_36;
        gout64 += g_0 * g_35 * g_36;
        gout65 += g_0 * g_34 * g_37;
        gout66 += g_1 * g_32 * g_38;
        gout67 += g_0 * g_33 * g_38;
        gout68 += g_0 * g_32 * g_39;
        gout69 += g_1 * g_30 * g_40;
        gout70 += g_0 * g_31 * g_40;
        gout71 += g_0 * g_30 * g_41;
        gout72 += g_5 * g_24 * g_42;
        gout73 += g_4 * g_25 * g_42;
        gout74 += g_4 * g_24 * g_43;
        gout75 += g_3 * g_26 * g_42;
        gout76 += g_2 * g_27 * g_42;
        gout77 += g_2 * g_26 * g_43;
        gout78 += g_3 * g_24 * g_44;
        gout79 += g_2 * g_25 * g_44;
        gout80 += g_2 * g_24 * g_45;
        gout81 += g_1 * g_28 * g_42;
        gout82 += g_0 * g_29 * g_42;
        gout83 += g_0 * g_28 * g_43;
        gout84 += g_1 * g_26 * g_44;
        gout85 += g_0 * g_27 * g_44;
        gout86 += g_0 * g_26 * g_45;
        gout87 += g_1 * g_24 * g_46;
        gout88 += g_0 * g_25 * g_46;
        gout89 += g_0 * g_24 * g_47;
        gout90 += g_5 * g_18 * g_48;
        gout91 += g_4 * g_19 * g_48;
        gout92 += g_4 * g_18 * g_49;
        gout93 += g_3 * g_20 * g_48;
        gout94 += g_2 * g_21 * g_48;
        gout95 += g_2 * g_20 * g_49;
        gout96 += g_3 * g_18 * g_50;
        gout97 += g_2 * g_19 * g_50;
        gout98 += g_2 * g_18 * g_51;
        gout99 += g_1 * g_22 * g_48;
        gout100 += g_0 * g_23 * g_48;
        gout101 += g_0 * g_22 * g_49;
        gout102 += g_1 * g_20 * g_50;
        gout103 += g_0 * g_21 * g_50;
        gout104 += g_0 * g_20 * g_51;
        gout105 += g_1 * g_18 * g_52;
        gout106 += g_0 * g_19 * g_52;
        gout107 += g_0 * g_18 * g_53;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        gout81 = reduce(gout81);
        gout82 = reduce(gout82);
        gout83 = reduce(gout83);
        gout84 = reduce(gout84);
        gout85 = reduce(gout85);
        gout86 = reduce(gout86);
        gout87 = reduce(gout87);
        gout88 = reduce(gout88);
        gout89 = reduce(gout89);
        gout90 = reduce(gout90);
        gout91 = reduce(gout91);
        gout92 = reduce(gout92);
        gout93 = reduce(gout93);
        gout94 = reduce(gout94);
        gout95 = reduce(gout95);
        gout96 = reduce(gout96);
        gout97 = reduce(gout97);
        gout98 = reduce(gout98);
        gout99 = reduce(gout99);
        gout100 = reduce(gout100);
        gout101 = reduce(gout101);
        gout102 = reduce(gout102);
        gout103 = reduce(gout103);
        gout104 = reduce(gout104);
        gout105 = reduce(gout105);
        gout106 = reduce(gout106);
        gout107 = reduce(gout107);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 1 * kstride, gout3);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout4);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout5);
    atomicAdd(peri + 2 * kstride, gout6);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout7);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout8);
    atomicAdd(peri + 3 * kstride, gout9);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout10);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout11);
    atomicAdd(peri + 4 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout14);
    atomicAdd(peri + 5 * kstride, gout15);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout16);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout17);
    atomicAdd(peri + 1 * lstride, gout18);
    atomicAdd(peri + 1 * istride + 1 * lstride, gout19);
    atomicAdd(peri + 2 * istride + 1 * lstride, gout20);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout21);
    atomicAdd(peri + 1 * istride + 1 * kstride + 1 * lstride, gout22);
    atomicAdd(peri + 2 * istride + 1 * kstride + 1 * lstride, gout23);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout24);
    atomicAdd(peri + 1 * istride + 2 * kstride + 1 * lstride, gout25);
    atomicAdd(peri + 2 * istride + 2 * kstride + 1 * lstride, gout26);
    atomicAdd(peri + 3 * kstride + 1 * lstride, gout27);
    atomicAdd(peri + 1 * istride + 3 * kstride + 1 * lstride, gout28);
    atomicAdd(peri + 2 * istride + 3 * kstride + 1 * lstride, gout29);
    atomicAdd(peri + 4 * kstride + 1 * lstride, gout30);
    atomicAdd(peri + 1 * istride + 4 * kstride + 1 * lstride, gout31);
    atomicAdd(peri + 2 * istride + 4 * kstride + 1 * lstride, gout32);
    atomicAdd(peri + 5 * kstride + 1 * lstride, gout33);
    atomicAdd(peri + 1 * istride + 5 * kstride + 1 * lstride, gout34);
    atomicAdd(peri + 2 * istride + 5 * kstride + 1 * lstride, gout35);
    atomicAdd(peri + 2 * lstride, gout36);
    atomicAdd(peri + 1 * istride + 2 * lstride, gout37);
    atomicAdd(peri + 2 * istride + 2 * lstride, gout38);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout39);
    atomicAdd(peri + 1 * istride + 1 * kstride + 2 * lstride, gout40);
    atomicAdd(peri + 2 * istride + 1 * kstride + 2 * lstride, gout41);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout42);
    atomicAdd(peri + 1 * istride + 2 * kstride + 2 * lstride, gout43);
    atomicAdd(peri + 2 * istride + 2 * kstride + 2 * lstride, gout44);
    atomicAdd(peri + 3 * kstride + 2 * lstride, gout45);
    atomicAdd(peri + 1 * istride + 3 * kstride + 2 * lstride, gout46);
    atomicAdd(peri + 2 * istride + 3 * kstride + 2 * lstride, gout47);
    atomicAdd(peri + 4 * kstride + 2 * lstride, gout48);
    atomicAdd(peri + 1 * istride + 4 * kstride + 2 * lstride, gout49);
    atomicAdd(peri + 2 * istride + 4 * kstride + 2 * lstride, gout50);
    atomicAdd(peri + 5 * kstride + 2 * lstride, gout51);
    atomicAdd(peri + 1 * istride + 5 * kstride + 2 * lstride, gout52);
    atomicAdd(peri + 2 * istride + 5 * kstride + 2 * lstride, gout53);
    atomicAdd(peri + 3 * lstride, gout54);
    atomicAdd(peri + 1 * istride + 3 * lstride, gout55);
    atomicAdd(peri + 2 * istride + 3 * lstride, gout56);
    atomicAdd(peri + 1 * kstride + 3 * lstride, gout57);
    atomicAdd(peri + 1 * istride + 1 * kstride + 3 * lstride, gout58);
    atomicAdd(peri + 2 * istride + 1 * kstride + 3 * lstride, gout59);
    atomicAdd(peri + 2 * kstride + 3 * lstride, gout60);
    atomicAdd(peri + 1 * istride + 2 * kstride + 3 * lstride, gout61);
    atomicAdd(peri + 2 * istride + 2 * kstride + 3 * lstride, gout62);
    atomicAdd(peri + 3 * kstride + 3 * lstride, gout63);
    atomicAdd(peri + 1 * istride + 3 * kstride + 3 * lstride, gout64);
    atomicAdd(peri + 2 * istride + 3 * kstride + 3 * lstride, gout65);
    atomicAdd(peri + 4 * kstride + 3 * lstride, gout66);
    atomicAdd(peri + 1 * istride + 4 * kstride + 3 * lstride, gout67);
    atomicAdd(peri + 2 * istride + 4 * kstride + 3 * lstride, gout68);
    atomicAdd(peri + 5 * kstride + 3 * lstride, gout69);
    atomicAdd(peri + 1 * istride + 5 * kstride + 3 * lstride, gout70);
    atomicAdd(peri + 2 * istride + 5 * kstride + 3 * lstride, gout71);
    atomicAdd(peri + 4 * lstride, gout72);
    atomicAdd(peri + 1 * istride + 4 * lstride, gout73);
    atomicAdd(peri + 2 * istride + 4 * lstride, gout74);
    atomicAdd(peri + 1 * kstride + 4 * lstride, gout75);
    atomicAdd(peri + 1 * istride + 1 * kstride + 4 * lstride, gout76);
    atomicAdd(peri + 2 * istride + 1 * kstride + 4 * lstride, gout77);
    atomicAdd(peri + 2 * kstride + 4 * lstride, gout78);
    atomicAdd(peri + 1 * istride + 2 * kstride + 4 * lstride, gout79);
    atomicAdd(peri + 2 * istride + 2 * kstride + 4 * lstride, gout80);
    atomicAdd(peri + 3 * kstride + 4 * lstride, gout81);
    atomicAdd(peri + 1 * istride + 3 * kstride + 4 * lstride, gout82);
    atomicAdd(peri + 2 * istride + 3 * kstride + 4 * lstride, gout83);
    atomicAdd(peri + 4 * kstride + 4 * lstride, gout84);
    atomicAdd(peri + 1 * istride + 4 * kstride + 4 * lstride, gout85);
    atomicAdd(peri + 2 * istride + 4 * kstride + 4 * lstride, gout86);
    atomicAdd(peri + 5 * kstride + 4 * lstride, gout87);
    atomicAdd(peri + 1 * istride + 5 * kstride + 4 * lstride, gout88);
    atomicAdd(peri + 2 * istride + 5 * kstride + 4 * lstride, gout89);
    atomicAdd(peri + 5 * lstride, gout90);
    atomicAdd(peri + 1 * istride + 5 * lstride, gout91);
    atomicAdd(peri + 2 * istride + 5 * lstride, gout92);
    atomicAdd(peri + 1 * kstride + 5 * lstride, gout93);
    atomicAdd(peri + 1 * istride + 1 * kstride + 5 * lstride, gout94);
    atomicAdd(peri + 2 * istride + 1 * kstride + 5 * lstride, gout95);
    atomicAdd(peri + 2 * kstride + 5 * lstride, gout96);
    atomicAdd(peri + 1 * istride + 2 * kstride + 5 * lstride, gout97);
    atomicAdd(peri + 2 * istride + 2 * kstride + 5 * lstride, gout98);
    atomicAdd(peri + 3 * kstride + 5 * lstride, gout99);
    atomicAdd(peri + 1 * istride + 3 * kstride + 5 * lstride, gout100);
    atomicAdd(peri + 2 * istride + 3 * kstride + 5 * lstride, gout101);
    atomicAdd(peri + 4 * kstride + 5 * lstride, gout102);
    atomicAdd(peri + 1 * istride + 4 * kstride + 5 * lstride, gout103);
    atomicAdd(peri + 2 * istride + 4 * kstride + 5 * lstride, gout104);
    atomicAdd(peri + 5 * kstride + 5 * lstride, gout105);
    atomicAdd(peri + 1 * istride + 5 * kstride + 5 * lstride, gout106);
    atomicAdd(peri + 2 * istride + 5 * kstride + 5 * lstride, gout107);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel1030(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c0px;
        double g_3 = c0px * c00x + b00;
        double g_4 = c0px * c0px + b01;
        double g_5 = b00 * c0px + b01 * c00x + c0px * g_3;
        double g_6 = c0px * (2 * b01 + g_4);
        double g_7 = 2 * b01 * g_3 + b00 * g_4 + c0px * g_5;
        double g_8 = 1;
        double g_9 = c00y;
        double g_10 = c0py;
        double g_11 = c0py * c00y + b00;
        double g_12 = c0py * c0py + b01;
        double g_13 = b00 * c0py + b01 * c00y + c0py * g_11;
        double g_14 = c0py * (2 * b01 + g_12);
        double g_15 = 2 * b01 * g_11 + b00 * g_12 + c0py * g_13;
        double g_16 = weight0 * fac;
        double g_17 = c00z * g_16;
        double g_18 = c0pz * g_16;
        double g_19 = b00 * g_16 + c0pz * g_17;
        double g_20 = b01 * g_16 + c0pz * g_18;
        double g_21 = b00 * g_18 + b01 * g_17 + c0pz * g_19;
        double g_22 = 2 * b01 * g_18 + c0pz * g_20;
        double g_23 = 2 * b01 * g_19 + b00 * g_20 + c0pz * g_21;
        gout0 += g_7 * g_8 * g_16;
        gout1 += g_6 * g_9 * g_16;
        gout2 += g_6 * g_8 * g_17;
        gout3 += g_5 * g_10 * g_16;
        gout4 += g_4 * g_11 * g_16;
        gout5 += g_4 * g_10 * g_17;
        gout6 += g_5 * g_8 * g_18;
        gout7 += g_4 * g_9 * g_18;
        gout8 += g_4 * g_8 * g_19;
        gout9 += g_3 * g_12 * g_16;
        gout10 += g_2 * g_13 * g_16;
        gout11 += g_2 * g_12 * g_17;
        gout12 += g_3 * g_10 * g_18;
        gout13 += g_2 * g_11 * g_18;
        gout14 += g_2 * g_10 * g_19;
        gout15 += g_3 * g_8 * g_20;
        gout16 += g_2 * g_9 * g_20;
        gout17 += g_2 * g_8 * g_21;
        gout18 += g_1 * g_14 * g_16;
        gout19 += g_0 * g_15 * g_16;
        gout20 += g_0 * g_14 * g_17;
        gout21 += g_1 * g_12 * g_18;
        gout22 += g_0 * g_13 * g_18;
        gout23 += g_0 * g_12 * g_19;
        gout24 += g_1 * g_10 * g_20;
        gout25 += g_0 * g_11 * g_20;
        gout26 += g_0 * g_10 * g_21;
        gout27 += g_1 * g_8 * g_22;
        gout28 += g_0 * g_9 * g_22;
        gout29 += g_0 * g_8 * g_23;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 1 * kstride, gout3);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout4);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout5);
    atomicAdd(peri + 2 * kstride, gout6);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout7);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout8);
    atomicAdd(peri + 3 * kstride, gout9);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout10);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout11);
    atomicAdd(peri + 4 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout14);
    atomicAdd(peri + 5 * kstride, gout15);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout16);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout17);
    atomicAdd(peri + 6 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 6 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 6 * kstride, gout20);
    atomicAdd(peri + 7 * kstride, gout21);
    atomicAdd(peri + 1 * istride + 7 * kstride, gout22);
    atomicAdd(peri + 2 * istride + 7 * kstride, gout23);
    atomicAdd(peri + 8 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 8 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 8 * kstride, gout26);
    atomicAdd(peri + 9 * kstride, gout27);
    atomicAdd(peri + 1 * istride + 9 * kstride, gout28);
    atomicAdd(peri + 2 * istride + 9 * kstride, gout29);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel1031(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c0px;
        double g_3 = c0px * c00x + b00;
        double g_4 = c0px * c0px + b01;
        double g_5 = b00 * c0px + b01 * c00x + c0px * g_3;
        double g_6 = c0px * (2 * b01 + g_4);
        double g_7 = 2 * b01 * g_3 + b00 * g_4 + c0px * g_5;
        double g_8 = c0px + xkxl;
        double g_9 = c00x * (c0px + xkxl) + b00;
        double g_10 = c0px * (c0px + xkxl) + b01;
        double g_11 = b00 * c0px + b01 * c00x + c0px * g_3 + xkxl * g_3;
        double g_12 = c0px * (2 * b01 + g_4) + xkxl * g_4;
        double g_13 = 2 * b01 * g_3 + b00 * g_4 + c0px * g_5 + xkxl * g_5;
        double g_14 = 3 * b01 * g_4 + c0px * g_6 + xkxl * g_6;
        double g_15 = 3 * b01 * g_5 + b00 * g_6 + c0px * g_7 + xkxl * g_7;
        double g_16 = 1;
        double g_17 = c00y;
        double g_18 = c0py;
        double g_19 = c0py * c00y + b00;
        double g_20 = c0py * c0py + b01;
        double g_21 = b00 * c0py + b01 * c00y + c0py * g_19;
        double g_22 = c0py * (2 * b01 + g_20);
        double g_23 = 2 * b01 * g_19 + b00 * g_20 + c0py * g_21;
        double g_24 = c0py + ykyl;
        double g_25 = c00y * (c0py + ykyl) + b00;
        double g_26 = c0py * (c0py + ykyl) + b01;
        double g_27 = b00 * c0py + b01 * c00y + c0py * g_19 + ykyl * g_19;
        double g_28 = c0py * (2 * b01 + g_20) + ykyl * g_20;
        double g_29 = 2 * b01 * g_19 + b00 * g_20 + c0py * g_21 + ykyl * g_21;
        double g_30 = 3 * b01 * g_20 + c0py * g_22 + ykyl * g_22;
        double g_31 = 3 * b01 * g_21 + b00 * g_22 + c0py * g_23 + ykyl * g_23;
        double g_32 = weight0 * fac;
        double g_33 = c00z * g_32;
        double g_34 = c0pz * g_32;
        double g_35 = b00 * g_32 + c0pz * g_33;
        double g_36 = b01 * g_32 + c0pz * g_34;
        double g_37 = b00 * g_34 + b01 * g_33 + c0pz * g_35;
        double g_38 = 2 * b01 * g_34 + c0pz * g_36;
        double g_39 = 2 * b01 * g_35 + b00 * g_36 + c0pz * g_37;
        double g_40 = g_32 * (c0pz + zkzl);
        double g_41 = b00 * g_32 + c0pz * g_33 + zkzl * g_33;
        double g_42 = b01 * g_32 + c0pz * g_34 + zkzl * g_34;
        double g_43 = b00 * g_34 + b01 * g_33 + c0pz * g_35 + zkzl * g_35;
        double g_44 = 2 * b01 * g_34 + c0pz * g_36 + zkzl * g_36;
        double g_45 = 2 * b01 * g_35 + b00 * g_36 + c0pz * g_37 + zkzl * g_37;
        double g_46 = 3 * b01 * g_36 + c0pz * g_38 + zkzl * g_38;
        double g_47 = 3 * b01 * g_37 + b00 * g_38 + c0pz * g_39 + zkzl * g_39;
        gout0 += g_15 * g_16 * g_32;
        gout1 += g_14 * g_17 * g_32;
        gout2 += g_14 * g_16 * g_33;
        gout3 += g_13 * g_18 * g_32;
        gout4 += g_12 * g_19 * g_32;
        gout5 += g_12 * g_18 * g_33;
        gout6 += g_13 * g_16 * g_34;
        gout7 += g_12 * g_17 * g_34;
        gout8 += g_12 * g_16 * g_35;
        gout9 += g_11 * g_20 * g_32;
        gout10 += g_10 * g_21 * g_32;
        gout11 += g_10 * g_20 * g_33;
        gout12 += g_11 * g_18 * g_34;
        gout13 += g_10 * g_19 * g_34;
        gout14 += g_10 * g_18 * g_35;
        gout15 += g_11 * g_16 * g_36;
        gout16 += g_10 * g_17 * g_36;
        gout17 += g_10 * g_16 * g_37;
        gout18 += g_9 * g_22 * g_32;
        gout19 += g_8 * g_23 * g_32;
        gout20 += g_8 * g_22 * g_33;
        gout21 += g_9 * g_20 * g_34;
        gout22 += g_8 * g_21 * g_34;
        gout23 += g_8 * g_20 * g_35;
        gout24 += g_9 * g_18 * g_36;
        gout25 += g_8 * g_19 * g_36;
        gout26 += g_8 * g_18 * g_37;
        gout27 += g_9 * g_16 * g_38;
        gout28 += g_8 * g_17 * g_38;
        gout29 += g_8 * g_16 * g_39;
        gout30 += g_7 * g_24 * g_32;
        gout31 += g_6 * g_25 * g_32;
        gout32 += g_6 * g_24 * g_33;
        gout33 += g_5 * g_26 * g_32;
        gout34 += g_4 * g_27 * g_32;
        gout35 += g_4 * g_26 * g_33;
        gout36 += g_5 * g_24 * g_34;
        gout37 += g_4 * g_25 * g_34;
        gout38 += g_4 * g_24 * g_35;
        gout39 += g_3 * g_28 * g_32;
        gout40 += g_2 * g_29 * g_32;
        gout41 += g_2 * g_28 * g_33;
        gout42 += g_3 * g_26 * g_34;
        gout43 += g_2 * g_27 * g_34;
        gout44 += g_2 * g_26 * g_35;
        gout45 += g_3 * g_24 * g_36;
        gout46 += g_2 * g_25 * g_36;
        gout47 += g_2 * g_24 * g_37;
        gout48 += g_1 * g_30 * g_32;
        gout49 += g_0 * g_31 * g_32;
        gout50 += g_0 * g_30 * g_33;
        gout51 += g_1 * g_28 * g_34;
        gout52 += g_0 * g_29 * g_34;
        gout53 += g_0 * g_28 * g_35;
        gout54 += g_1 * g_26 * g_36;
        gout55 += g_0 * g_27 * g_36;
        gout56 += g_0 * g_26 * g_37;
        gout57 += g_1 * g_24 * g_38;
        gout58 += g_0 * g_25 * g_38;
        gout59 += g_0 * g_24 * g_39;
        gout60 += g_7 * g_16 * g_40;
        gout61 += g_6 * g_17 * g_40;
        gout62 += g_6 * g_16 * g_41;
        gout63 += g_5 * g_18 * g_40;
        gout64 += g_4 * g_19 * g_40;
        gout65 += g_4 * g_18 * g_41;
        gout66 += g_5 * g_16 * g_42;
        gout67 += g_4 * g_17 * g_42;
        gout68 += g_4 * g_16 * g_43;
        gout69 += g_3 * g_20 * g_40;
        gout70 += g_2 * g_21 * g_40;
        gout71 += g_2 * g_20 * g_41;
        gout72 += g_3 * g_18 * g_42;
        gout73 += g_2 * g_19 * g_42;
        gout74 += g_2 * g_18 * g_43;
        gout75 += g_3 * g_16 * g_44;
        gout76 += g_2 * g_17 * g_44;
        gout77 += g_2 * g_16 * g_45;
        gout78 += g_1 * g_22 * g_40;
        gout79 += g_0 * g_23 * g_40;
        gout80 += g_0 * g_22 * g_41;
        gout81 += g_1 * g_20 * g_42;
        gout82 += g_0 * g_21 * g_42;
        gout83 += g_0 * g_20 * g_43;
        gout84 += g_1 * g_18 * g_44;
        gout85 += g_0 * g_19 * g_44;
        gout86 += g_0 * g_18 * g_45;
        gout87 += g_1 * g_16 * g_46;
        gout88 += g_0 * g_17 * g_46;
        gout89 += g_0 * g_16 * g_47;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        gout81 = reduce(gout81);
        gout82 = reduce(gout82);
        gout83 = reduce(gout83);
        gout84 = reduce(gout84);
        gout85 = reduce(gout85);
        gout86 = reduce(gout86);
        gout87 = reduce(gout87);
        gout88 = reduce(gout88);
        gout89 = reduce(gout89);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 1 * kstride, gout3);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout4);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout5);
    atomicAdd(peri + 2 * kstride, gout6);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout7);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout8);
    atomicAdd(peri + 3 * kstride, gout9);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout10);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout11);
    atomicAdd(peri + 4 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout14);
    atomicAdd(peri + 5 * kstride, gout15);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout16);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout17);
    atomicAdd(peri + 6 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 6 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 6 * kstride, gout20);
    atomicAdd(peri + 7 * kstride, gout21);
    atomicAdd(peri + 1 * istride + 7 * kstride, gout22);
    atomicAdd(peri + 2 * istride + 7 * kstride, gout23);
    atomicAdd(peri + 8 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 8 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 8 * kstride, gout26);
    atomicAdd(peri + 9 * kstride, gout27);
    atomicAdd(peri + 1 * istride + 9 * kstride, gout28);
    atomicAdd(peri + 2 * istride + 9 * kstride, gout29);
    atomicAdd(peri + 1 * lstride, gout30);
    atomicAdd(peri + 1 * istride + 1 * lstride, gout31);
    atomicAdd(peri + 2 * istride + 1 * lstride, gout32);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout33);
    atomicAdd(peri + 1 * istride + 1 * kstride + 1 * lstride, gout34);
    atomicAdd(peri + 2 * istride + 1 * kstride + 1 * lstride, gout35);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout36);
    atomicAdd(peri + 1 * istride + 2 * kstride + 1 * lstride, gout37);
    atomicAdd(peri + 2 * istride + 2 * kstride + 1 * lstride, gout38);
    atomicAdd(peri + 3 * kstride + 1 * lstride, gout39);
    atomicAdd(peri + 1 * istride + 3 * kstride + 1 * lstride, gout40);
    atomicAdd(peri + 2 * istride + 3 * kstride + 1 * lstride, gout41);
    atomicAdd(peri + 4 * kstride + 1 * lstride, gout42);
    atomicAdd(peri + 1 * istride + 4 * kstride + 1 * lstride, gout43);
    atomicAdd(peri + 2 * istride + 4 * kstride + 1 * lstride, gout44);
    atomicAdd(peri + 5 * kstride + 1 * lstride, gout45);
    atomicAdd(peri + 1 * istride + 5 * kstride + 1 * lstride, gout46);
    atomicAdd(peri + 2 * istride + 5 * kstride + 1 * lstride, gout47);
    atomicAdd(peri + 6 * kstride + 1 * lstride, gout48);
    atomicAdd(peri + 1 * istride + 6 * kstride + 1 * lstride, gout49);
    atomicAdd(peri + 2 * istride + 6 * kstride + 1 * lstride, gout50);
    atomicAdd(peri + 7 * kstride + 1 * lstride, gout51);
    atomicAdd(peri + 1 * istride + 7 * kstride + 1 * lstride, gout52);
    atomicAdd(peri + 2 * istride + 7 * kstride + 1 * lstride, gout53);
    atomicAdd(peri + 8 * kstride + 1 * lstride, gout54);
    atomicAdd(peri + 1 * istride + 8 * kstride + 1 * lstride, gout55);
    atomicAdd(peri + 2 * istride + 8 * kstride + 1 * lstride, gout56);
    atomicAdd(peri + 9 * kstride + 1 * lstride, gout57);
    atomicAdd(peri + 1 * istride + 9 * kstride + 1 * lstride, gout58);
    atomicAdd(peri + 2 * istride + 9 * kstride + 1 * lstride, gout59);
    atomicAdd(peri + 2 * lstride, gout60);
    atomicAdd(peri + 1 * istride + 2 * lstride, gout61);
    atomicAdd(peri + 2 * istride + 2 * lstride, gout62);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout63);
    atomicAdd(peri + 1 * istride + 1 * kstride + 2 * lstride, gout64);
    atomicAdd(peri + 2 * istride + 1 * kstride + 2 * lstride, gout65);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout66);
    atomicAdd(peri + 1 * istride + 2 * kstride + 2 * lstride, gout67);
    atomicAdd(peri + 2 * istride + 2 * kstride + 2 * lstride, gout68);
    atomicAdd(peri + 3 * kstride + 2 * lstride, gout69);
    atomicAdd(peri + 1 * istride + 3 * kstride + 2 * lstride, gout70);
    atomicAdd(peri + 2 * istride + 3 * kstride + 2 * lstride, gout71);
    atomicAdd(peri + 4 * kstride + 2 * lstride, gout72);
    atomicAdd(peri + 1 * istride + 4 * kstride + 2 * lstride, gout73);
    atomicAdd(peri + 2 * istride + 4 * kstride + 2 * lstride, gout74);
    atomicAdd(peri + 5 * kstride + 2 * lstride, gout75);
    atomicAdd(peri + 1 * istride + 5 * kstride + 2 * lstride, gout76);
    atomicAdd(peri + 2 * istride + 5 * kstride + 2 * lstride, gout77);
    atomicAdd(peri + 6 * kstride + 2 * lstride, gout78);
    atomicAdd(peri + 1 * istride + 6 * kstride + 2 * lstride, gout79);
    atomicAdd(peri + 2 * istride + 6 * kstride + 2 * lstride, gout80);
    atomicAdd(peri + 7 * kstride + 2 * lstride, gout81);
    atomicAdd(peri + 1 * istride + 7 * kstride + 2 * lstride, gout82);
    atomicAdd(peri + 2 * istride + 7 * kstride + 2 * lstride, gout83);
    atomicAdd(peri + 8 * kstride + 2 * lstride, gout84);
    atomicAdd(peri + 1 * istride + 8 * kstride + 2 * lstride, gout85);
    atomicAdd(peri + 2 * istride + 8 * kstride + 2 * lstride, gout86);
    atomicAdd(peri + 9 * kstride + 2 * lstride, gout87);
    atomicAdd(peri + 1 * istride + 9 * kstride + 2 * lstride, gout88);
    atomicAdd(peri + 2 * istride + 9 * kstride + 2 * lstride, gout89);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel1111(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x + xixj;
        double g_3 = c00x * (c00x + xixj) + b10;
        double g_4 = c0px;
        double g_5 = c0px * c00x + b00;
        double g_6 = c0px * (c00x + xixj) + b00;
        double g_7 = b00 * c00x + b10 * c0px + c00x * g_5 + xixj * g_5;
        double g_8 = c0px + xkxl;
        double g_9 = c00x * (c0px + xkxl) + b00;
        double g_10 = xkxl * (xixj + c00x) + xixj * c0px + c0px * c00x + b00;
        double g_11 = xkxl * (xixj * c00x + c00x * c00x + b10) + xixj * g_5 +
                      c00x * g_5 + b10 * c0px + b00 * c00x;
        double g_12 = c0px * (c0px + xkxl) + b01;
        double g_13 = b00 * c0px + b01 * c00x + c0px * g_5 + xkxl * g_5;
        double g_14 = xkxl * (xixj * c0px + c0px * c00x + b00) +
                      xixj * (c0px * c0px + b01) + c0px * g_5 + b01 * c00x +
                      b00 * c0px;
        double g_15 =
            xkxl * (xixj * g_5 + c00x * g_5 + b10 * c0px + b00 * c00x) +
            xixj * (c0px * g_5 + b01 * c00x + b00 * c0px) +
            c00x * (c0px * g_5 + b01 * c00x + b00 * c0px) +
            b10 * (c0px * c0px + b01) + 2 * b00 * g_5;
        double g_16 = 1;
        double g_17 = c00y;
        double g_18 = c00y + yiyj;
        double g_19 = c00y * (c00y + yiyj) + b10;
        double g_20 = c0py;
        double g_21 = c0py * c00y + b00;
        double g_22 = c0py * (c00y + yiyj) + b00;
        double g_23 = b00 * c00y + b10 * c0py + c00y * g_21 + yiyj * g_21;
        double g_24 = c0py + ykyl;
        double g_25 = c00y * (c0py + ykyl) + b00;
        double g_26 = ykyl * (yiyj + c00y) + yiyj * c0py + c0py * c00y + b00;
        double g_27 = ykyl * (yiyj * c00y + c00y * c00y + b10) + yiyj * g_21 +
                      c00y * g_21 + b10 * c0py + b00 * c00y;
        double g_28 = c0py * (c0py + ykyl) + b01;
        double g_29 = b00 * c0py + b01 * c00y + c0py * g_21 + ykyl * g_21;
        double g_30 = ykyl * (yiyj * c0py + c0py * c00y + b00) +
                      yiyj * (c0py * c0py + b01) + c0py * g_21 + b01 * c00y +
                      b00 * c0py;
        double g_31 =
            ykyl * (yiyj * g_21 + c00y * g_21 + b10 * c0py + b00 * c00y) +
            yiyj * (c0py * g_21 + b01 * c00y + b00 * c0py) +
            c00y * (c0py * g_21 + b01 * c00y + b00 * c0py) +
            b10 * (c0py * c0py + b01) + 2 * b00 * g_21;
        double g_32 = weight0 * fac;
        double g_33 = c00z * g_32;
        double g_34 = g_32 * (c00z + zizj);
        double g_35 = b10 * g_32 + c00z * g_33 + zizj * g_33;
        double g_36 = c0pz * g_32;
        double g_37 = b00 * g_32 + c0pz * g_33;
        double g_38 = b00 * g_32 + c0pz * g_33 + zizj * g_36;
        double g_39 = b00 * g_33 + b10 * g_36 + c00z * g_37 + zizj * g_37;
        double g_40 = g_32 * (c0pz + zkzl);
        double g_41 = b00 * g_32 + c0pz * g_33 + zkzl * g_33;
        double g_42 = zkzl * (zizj * g_32 + c00z * g_32) + zizj * g_36 +
                      c0pz * g_33 + b00 * g_32;
        double g_43 = zkzl * (zizj * g_33 + c00z * g_33 + b10 * g_32) +
                      zizj * g_37 + c00z * g_37 + b10 * g_36 + b00 * g_33;
        double g_44 = b01 * g_32 + c0pz * g_36 + zkzl * g_36;
        double g_45 = b00 * g_36 + b01 * g_33 + c0pz * g_37 + zkzl * g_37;
        double g_46 = zkzl * (zizj * g_36 + c0pz * g_33 + b00 * g_32) +
                      zizj * (c0pz * g_36 + b01 * g_32) + c0pz * g_37 +
                      b01 * g_33 + b00 * g_36;
        double g_47 =
            zkzl * (zizj * g_37 + c00z * g_37 + b10 * g_36 + b00 * g_33) +
            zizj * (c0pz * g_37 + b01 * g_33 + b00 * g_36) +
            c00z * (c0pz * g_37 + b01 * g_33 + b00 * g_36) +
            b10 * (c0pz * g_36 + b01 * g_32) + 2 * b00 * g_37;
        gout0 += g_15 * g_16 * g_32;
        gout1 += g_14 * g_17 * g_32;
        gout2 += g_14 * g_16 * g_33;
        gout3 += g_13 * g_18 * g_32;
        gout4 += g_12 * g_19 * g_32;
        gout5 += g_12 * g_18 * g_33;
        gout6 += g_13 * g_16 * g_34;
        gout7 += g_12 * g_17 * g_34;
        gout8 += g_12 * g_16 * g_35;
        gout9 += g_11 * g_20 * g_32;
        gout10 += g_10 * g_21 * g_32;
        gout11 += g_10 * g_20 * g_33;
        gout12 += g_9 * g_22 * g_32;
        gout13 += g_8 * g_23 * g_32;
        gout14 += g_8 * g_22 * g_33;
        gout15 += g_9 * g_20 * g_34;
        gout16 += g_8 * g_21 * g_34;
        gout17 += g_8 * g_20 * g_35;
        gout18 += g_11 * g_16 * g_36;
        gout19 += g_10 * g_17 * g_36;
        gout20 += g_10 * g_16 * g_37;
        gout21 += g_9 * g_18 * g_36;
        gout22 += g_8 * g_19 * g_36;
        gout23 += g_8 * g_18 * g_37;
        gout24 += g_9 * g_16 * g_38;
        gout25 += g_8 * g_17 * g_38;
        gout26 += g_8 * g_16 * g_39;
        gout27 += g_7 * g_24 * g_32;
        gout28 += g_6 * g_25 * g_32;
        gout29 += g_6 * g_24 * g_33;
        gout30 += g_5 * g_26 * g_32;
        gout31 += g_4 * g_27 * g_32;
        gout32 += g_4 * g_26 * g_33;
        gout33 += g_5 * g_24 * g_34;
        gout34 += g_4 * g_25 * g_34;
        gout35 += g_4 * g_24 * g_35;
        gout36 += g_3 * g_28 * g_32;
        gout37 += g_2 * g_29 * g_32;
        gout38 += g_2 * g_28 * g_33;
        gout39 += g_1 * g_30 * g_32;
        gout40 += g_0 * g_31 * g_32;
        gout41 += g_0 * g_30 * g_33;
        gout42 += g_1 * g_28 * g_34;
        gout43 += g_0 * g_29 * g_34;
        gout44 += g_0 * g_28 * g_35;
        gout45 += g_3 * g_24 * g_36;
        gout46 += g_2 * g_25 * g_36;
        gout47 += g_2 * g_24 * g_37;
        gout48 += g_1 * g_26 * g_36;
        gout49 += g_0 * g_27 * g_36;
        gout50 += g_0 * g_26 * g_37;
        gout51 += g_1 * g_24 * g_38;
        gout52 += g_0 * g_25 * g_38;
        gout53 += g_0 * g_24 * g_39;
        gout54 += g_7 * g_16 * g_40;
        gout55 += g_6 * g_17 * g_40;
        gout56 += g_6 * g_16 * g_41;
        gout57 += g_5 * g_18 * g_40;
        gout58 += g_4 * g_19 * g_40;
        gout59 += g_4 * g_18 * g_41;
        gout60 += g_5 * g_16 * g_42;
        gout61 += g_4 * g_17 * g_42;
        gout62 += g_4 * g_16 * g_43;
        gout63 += g_3 * g_20 * g_40;
        gout64 += g_2 * g_21 * g_40;
        gout65 += g_2 * g_20 * g_41;
        gout66 += g_1 * g_22 * g_40;
        gout67 += g_0 * g_23 * g_40;
        gout68 += g_0 * g_22 * g_41;
        gout69 += g_1 * g_20 * g_42;
        gout70 += g_0 * g_21 * g_42;
        gout71 += g_0 * g_20 * g_43;
        gout72 += g_3 * g_16 * g_44;
        gout73 += g_2 * g_17 * g_44;
        gout74 += g_2 * g_16 * g_45;
        gout75 += g_1 * g_18 * g_44;
        gout76 += g_0 * g_19 * g_44;
        gout77 += g_0 * g_18 * g_45;
        gout78 += g_1 * g_16 * g_46;
        gout79 += g_0 * g_17 * g_46;
        gout80 += g_0 * g_16 * g_47;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 1 * jstride, gout3);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout4);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout5);
    atomicAdd(peri + 2 * jstride, gout6);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout7);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout8);
    atomicAdd(peri + 1 * kstride, gout9);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout10);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 1 * jstride + 1 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * kstride, gout14);
    atomicAdd(peri + 2 * jstride + 1 * kstride, gout15);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * kstride, gout16);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * kstride, gout17);
    atomicAdd(peri + 2 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout20);
    atomicAdd(peri + 1 * jstride + 2 * kstride, gout21);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * kstride, gout22);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * kstride, gout23);
    atomicAdd(peri + 2 * jstride + 2 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * kstride, gout26);
    atomicAdd(peri + 1 * lstride, gout27);
    atomicAdd(peri + 1 * istride + 1 * lstride, gout28);
    atomicAdd(peri + 2 * istride + 1 * lstride, gout29);
    atomicAdd(peri + 1 * jstride + 1 * lstride, gout30);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * lstride, gout31);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * lstride, gout32);
    atomicAdd(peri + 2 * jstride + 1 * lstride, gout33);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * lstride, gout34);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * lstride, gout35);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout36);
    atomicAdd(peri + 1 * istride + 1 * kstride + 1 * lstride, gout37);
    atomicAdd(peri + 2 * istride + 1 * kstride + 1 * lstride, gout38);
    atomicAdd(peri + 1 * jstride + 1 * kstride + 1 * lstride, gout39);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 1 * kstride + 1 * lstride, gout40);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 1 * kstride + 1 * lstride, gout41);
    atomicAdd(peri + 2 * jstride + 1 * kstride + 1 * lstride, gout42);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 1 * kstride + 1 * lstride, gout43);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 1 * kstride + 1 * lstride, gout44);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout45);
    atomicAdd(peri + 1 * istride + 2 * kstride + 1 * lstride, gout46);
    atomicAdd(peri + 2 * istride + 2 * kstride + 1 * lstride, gout47);
    atomicAdd(peri + 1 * jstride + 2 * kstride + 1 * lstride, gout48);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 2 * kstride + 1 * lstride, gout49);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 2 * kstride + 1 * lstride, gout50);
    atomicAdd(peri + 2 * jstride + 2 * kstride + 1 * lstride, gout51);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 2 * kstride + 1 * lstride, gout52);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 2 * kstride + 1 * lstride, gout53);
    atomicAdd(peri + 2 * lstride, gout54);
    atomicAdd(peri + 1 * istride + 2 * lstride, gout55);
    atomicAdd(peri + 2 * istride + 2 * lstride, gout56);
    atomicAdd(peri + 1 * jstride + 2 * lstride, gout57);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * lstride, gout58);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * lstride, gout59);
    atomicAdd(peri + 2 * jstride + 2 * lstride, gout60);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * lstride, gout61);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * lstride, gout62);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout63);
    atomicAdd(peri + 1 * istride + 1 * kstride + 2 * lstride, gout64);
    atomicAdd(peri + 2 * istride + 1 * kstride + 2 * lstride, gout65);
    atomicAdd(peri + 1 * jstride + 1 * kstride + 2 * lstride, gout66);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 1 * kstride + 2 * lstride, gout67);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 1 * kstride + 2 * lstride, gout68);
    atomicAdd(peri + 2 * jstride + 1 * kstride + 2 * lstride, gout69);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 1 * kstride + 2 * lstride, gout70);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 1 * kstride + 2 * lstride, gout71);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout72);
    atomicAdd(peri + 1 * istride + 2 * kstride + 2 * lstride, gout73);
    atomicAdd(peri + 2 * istride + 2 * kstride + 2 * lstride, gout74);
    atomicAdd(peri + 1 * jstride + 2 * kstride + 2 * lstride, gout75);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 2 * kstride + 2 * lstride, gout76);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 2 * kstride + 2 * lstride, gout77);
    atomicAdd(peri + 2 * jstride + 2 * kstride + 2 * lstride, gout78);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 2 * kstride + 2 * lstride, gout79);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 2 * kstride + 2 * lstride, gout80);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel1120(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x + xixj;
        double g_3 = c00x * (c00x + xixj) + b10;
        double g_4 = c0px;
        double g_5 = c0px * c00x + b00;
        double g_6 = c0px * (c00x + xixj) + b00;
        double g_7 = b00 * c00x + b10 * c0px + c00x * g_5 + xixj * g_5;
        double g_8 = c0px * c0px + b01;
        double g_9 = b00 * c0px + b01 * c00x + c0px * g_5;
        double g_10 = b00 * c0px + b01 * c00x + c0px * g_5 + xixj * g_8;
        double g_11 = 2 * b00 * g_5 + b10 * g_8 + c00x * g_9 + xixj * g_9;
        double g_12 = 1;
        double g_13 = c00y;
        double g_14 = c00y + yiyj;
        double g_15 = c00y * (c00y + yiyj) + b10;
        double g_16 = c0py;
        double g_17 = c0py * c00y + b00;
        double g_18 = c0py * (c00y + yiyj) + b00;
        double g_19 = b00 * c00y + b10 * c0py + c00y * g_17 + yiyj * g_17;
        double g_20 = c0py * c0py + b01;
        double g_21 = b00 * c0py + b01 * c00y + c0py * g_17;
        double g_22 = b00 * c0py + b01 * c00y + c0py * g_17 + yiyj * g_20;
        double g_23 = 2 * b00 * g_17 + b10 * g_20 + c00y * g_21 + yiyj * g_21;
        double g_24 = weight0 * fac;
        double g_25 = c00z * g_24;
        double g_26 = g_24 * (c00z + zizj);
        double g_27 = b10 * g_24 + c00z * g_25 + zizj * g_25;
        double g_28 = c0pz * g_24;
        double g_29 = b00 * g_24 + c0pz * g_25;
        double g_30 = b00 * g_24 + c0pz * g_25 + zizj * g_28;
        double g_31 = b00 * g_25 + b10 * g_28 + c00z * g_29 + zizj * g_29;
        double g_32 = b01 * g_24 + c0pz * g_28;
        double g_33 = b00 * g_28 + b01 * g_25 + c0pz * g_29;
        double g_34 = b00 * g_28 + b01 * g_25 + c0pz * g_29 + zizj * g_32;
        double g_35 = 2 * b00 * g_29 + b10 * g_32 + c00z * g_33 + zizj * g_33;
        gout0 += g_11 * g_12 * g_24;
        gout1 += g_10 * g_13 * g_24;
        gout2 += g_10 * g_12 * g_25;
        gout3 += g_9 * g_14 * g_24;
        gout4 += g_8 * g_15 * g_24;
        gout5 += g_8 * g_14 * g_25;
        gout6 += g_9 * g_12 * g_26;
        gout7 += g_8 * g_13 * g_26;
        gout8 += g_8 * g_12 * g_27;
        gout9 += g_7 * g_16 * g_24;
        gout10 += g_6 * g_17 * g_24;
        gout11 += g_6 * g_16 * g_25;
        gout12 += g_5 * g_18 * g_24;
        gout13 += g_4 * g_19 * g_24;
        gout14 += g_4 * g_18 * g_25;
        gout15 += g_5 * g_16 * g_26;
        gout16 += g_4 * g_17 * g_26;
        gout17 += g_4 * g_16 * g_27;
        gout18 += g_7 * g_12 * g_28;
        gout19 += g_6 * g_13 * g_28;
        gout20 += g_6 * g_12 * g_29;
        gout21 += g_5 * g_14 * g_28;
        gout22 += g_4 * g_15 * g_28;
        gout23 += g_4 * g_14 * g_29;
        gout24 += g_5 * g_12 * g_30;
        gout25 += g_4 * g_13 * g_30;
        gout26 += g_4 * g_12 * g_31;
        gout27 += g_3 * g_20 * g_24;
        gout28 += g_2 * g_21 * g_24;
        gout29 += g_2 * g_20 * g_25;
        gout30 += g_1 * g_22 * g_24;
        gout31 += g_0 * g_23 * g_24;
        gout32 += g_0 * g_22 * g_25;
        gout33 += g_1 * g_20 * g_26;
        gout34 += g_0 * g_21 * g_26;
        gout35 += g_0 * g_20 * g_27;
        gout36 += g_3 * g_16 * g_28;
        gout37 += g_2 * g_17 * g_28;
        gout38 += g_2 * g_16 * g_29;
        gout39 += g_1 * g_18 * g_28;
        gout40 += g_0 * g_19 * g_28;
        gout41 += g_0 * g_18 * g_29;
        gout42 += g_1 * g_16 * g_30;
        gout43 += g_0 * g_17 * g_30;
        gout44 += g_0 * g_16 * g_31;
        gout45 += g_3 * g_12 * g_32;
        gout46 += g_2 * g_13 * g_32;
        gout47 += g_2 * g_12 * g_33;
        gout48 += g_1 * g_14 * g_32;
        gout49 += g_0 * g_15 * g_32;
        gout50 += g_0 * g_14 * g_33;
        gout51 += g_1 * g_12 * g_34;
        gout52 += g_0 * g_13 * g_34;
        gout53 += g_0 * g_12 * g_35;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 1 * jstride, gout3);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout4);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout5);
    atomicAdd(peri + 2 * jstride, gout6);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout7);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout8);
    atomicAdd(peri + 1 * kstride, gout9);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout10);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 1 * jstride + 1 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * kstride, gout14);
    atomicAdd(peri + 2 * jstride + 1 * kstride, gout15);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * kstride, gout16);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * kstride, gout17);
    atomicAdd(peri + 2 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout20);
    atomicAdd(peri + 1 * jstride + 2 * kstride, gout21);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * kstride, gout22);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * kstride, gout23);
    atomicAdd(peri + 2 * jstride + 2 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * kstride, gout26);
    atomicAdd(peri + 3 * kstride, gout27);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout28);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout29);
    atomicAdd(peri + 1 * jstride + 3 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 1 * jstride + 3 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 1 * jstride + 3 * kstride, gout32);
    atomicAdd(peri + 2 * jstride + 3 * kstride, gout33);
    atomicAdd(peri + 1 * istride + 2 * jstride + 3 * kstride, gout34);
    atomicAdd(peri + 2 * istride + 2 * jstride + 3 * kstride, gout35);
    atomicAdd(peri + 4 * kstride, gout36);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout37);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout38);
    atomicAdd(peri + 1 * jstride + 4 * kstride, gout39);
    atomicAdd(peri + 1 * istride + 1 * jstride + 4 * kstride, gout40);
    atomicAdd(peri + 2 * istride + 1 * jstride + 4 * kstride, gout41);
    atomicAdd(peri + 2 * jstride + 4 * kstride, gout42);
    atomicAdd(peri + 1 * istride + 2 * jstride + 4 * kstride, gout43);
    atomicAdd(peri + 2 * istride + 2 * jstride + 4 * kstride, gout44);
    atomicAdd(peri + 5 * kstride, gout45);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout46);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout47);
    atomicAdd(peri + 1 * jstride + 5 * kstride, gout48);
    atomicAdd(peri + 1 * istride + 1 * jstride + 5 * kstride, gout49);
    atomicAdd(peri + 2 * istride + 1 * jstride + 5 * kstride, gout50);
    atomicAdd(peri + 2 * jstride + 5 * kstride, gout51);
    atomicAdd(peri + 1 * istride + 2 * jstride + 5 * kstride, gout52);
    atomicAdd(peri + 2 * istride + 2 * jstride + 5 * kstride, gout53);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel1121(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x + xixj;
        double g_3 = c00x * (c00x + xixj) + b10;
        double g_4 = c0px;
        double g_5 = c0px * c00x + b00;
        double g_6 = c0px * (c00x + xixj) + b00;
        double g_7 = b00 * c00x + b10 * c0px + c00x * g_5 + xixj * g_5;
        double g_8 = c0px * c0px + b01;
        double g_9 = b00 * c0px + b01 * c00x + c0px * g_5;
        double g_10 = b00 * c0px + b01 * c00x + c0px * g_5 + xixj * g_8;
        double g_11 = 2 * b00 * g_5 + b10 * g_8 + c00x * g_9 + xixj * g_9;
        double g_12 = c0px + xkxl;
        double g_13 = c00x * (c0px + xkxl) + b00;
        double g_14 = xkxl * (xixj + c00x) + xixj * c0px + c0px * c00x + b00;
        double g_15 = xkxl * (xixj * c00x + c00x * c00x + b10) + xixj * g_5 +
                      c00x * g_5 + b10 * c0px + b00 * c00x;
        double g_16 = c0px * (c0px + xkxl) + b01;
        double g_17 = b00 * c0px + b01 * c00x + c0px * g_5 + xkxl * g_5;
        double g_18 = xkxl * (xixj * c0px + c0px * c00x + b00) + xixj * g_8 +
                      c0px * g_5 + b01 * c00x + b00 * c0px;
        double g_19 =
            xkxl * (xixj * g_5 + c00x * g_5 + b10 * c0px + b00 * c00x) +
            xixj * g_9 + c00x * g_9 + b10 * g_8 + 2 * b00 * g_5;
        double g_20 = c0px * (2 * b01 + g_8) + xkxl * g_8;
        double g_21 = 2 * b01 * g_5 + b00 * g_8 + c0px * g_9 + xkxl * g_9;
        double g_22 =
            xkxl * (xixj * g_8 + c0px * g_5 + b01 * c00x + b00 * c0px) +
            xixj * (c0px * g_8 + 2 * b01 * c0px) + c0px * g_9 + 2 * b01 * g_5 +
            b00 * g_8;
        double g_23 =
            xkxl * (xixj * g_9 + c00x * g_9 + b10 * g_8 + 2 * b00 * g_5) +
            xixj * (c0px * g_9 + 2 * b01 * g_5 + b00 * g_8) +
            c00x * (c0px * g_9 + 2 * b01 * g_5 + b00 * g_8) +
            b10 * (c0px * g_8 + 2 * b01 * c0px) + 3 * b00 * g_9;
        double g_24 = 1;
        double g_25 = c00y;
        double g_26 = c00y + yiyj;
        double g_27 = c00y * (c00y + yiyj) + b10;
        double g_28 = c0py;
        double g_29 = c0py * c00y + b00;
        double g_30 = c0py * (c00y + yiyj) + b00;
        double g_31 = b00 * c00y + b10 * c0py + c00y * g_29 + yiyj * g_29;
        double g_32 = c0py * c0py + b01;
        double g_33 = b00 * c0py + b01 * c00y + c0py * g_29;
        double g_34 = b00 * c0py + b01 * c00y + c0py * g_29 + yiyj * g_32;
        double g_35 = 2 * b00 * g_29 + b10 * g_32 + c00y * g_33 + yiyj * g_33;
        double g_36 = c0py + ykyl;
        double g_37 = c00y * (c0py + ykyl) + b00;
        double g_38 = ykyl * (yiyj + c00y) + yiyj * c0py + c0py * c00y + b00;
        double g_39 = ykyl * (yiyj * c00y + c00y * c00y + b10) + yiyj * g_29 +
                      c00y * g_29 + b10 * c0py + b00 * c00y;
        double g_40 = c0py * (c0py + ykyl) + b01;
        double g_41 = b00 * c0py + b01 * c00y + c0py * g_29 + ykyl * g_29;
        double g_42 = ykyl * (yiyj * c0py + c0py * c00y + b00) + yiyj * g_32 +
                      c0py * g_29 + b01 * c00y + b00 * c0py;
        double g_43 =
            ykyl * (yiyj * g_29 + c00y * g_29 + b10 * c0py + b00 * c00y) +
            yiyj * g_33 + c00y * g_33 + b10 * g_32 + 2 * b00 * g_29;
        double g_44 = c0py * (2 * b01 + g_32) + ykyl * g_32;
        double g_45 = 2 * b01 * g_29 + b00 * g_32 + c0py * g_33 + ykyl * g_33;
        double g_46 =
            ykyl * (yiyj * g_32 + c0py * g_29 + b01 * c00y + b00 * c0py) +
            yiyj * (c0py * g_32 + 2 * b01 * c0py) + c0py * g_33 +
            2 * b01 * g_29 + b00 * g_32;
        double g_47 =
            ykyl * (yiyj * g_33 + c00y * g_33 + b10 * g_32 + 2 * b00 * g_29) +
            yiyj * (c0py * g_33 + 2 * b01 * g_29 + b00 * g_32) +
            c00y * (c0py * g_33 + 2 * b01 * g_29 + b00 * g_32) +
            b10 * (c0py * g_32 + 2 * b01 * c0py) + 3 * b00 * g_33;
        double g_48 = weight0 * fac;
        double g_49 = c00z * g_48;
        double g_50 = g_48 * (c00z + zizj);
        double g_51 = b10 * g_48 + c00z * g_49 + zizj * g_49;
        double g_52 = c0pz * g_48;
        double g_53 = b00 * g_48 + c0pz * g_49;
        double g_54 = b00 * g_48 + c0pz * g_49 + zizj * g_52;
        double g_55 = b00 * g_49 + b10 * g_52 + c00z * g_53 + zizj * g_53;
        double g_56 = b01 * g_48 + c0pz * g_52;
        double g_57 = b00 * g_52 + b01 * g_49 + c0pz * g_53;
        double g_58 = b00 * g_52 + b01 * g_49 + c0pz * g_53 + zizj * g_56;
        double g_59 = 2 * b00 * g_53 + b10 * g_56 + c00z * g_57 + zizj * g_57;
        double g_60 = g_48 * (c0pz + zkzl);
        double g_61 = b00 * g_48 + c0pz * g_49 + zkzl * g_49;
        double g_62 = zkzl * (zizj * g_48 + c00z * g_48) + zizj * g_52 +
                      c0pz * g_49 + b00 * g_48;
        double g_63 = zkzl * (zizj * g_49 + c00z * g_49 + b10 * g_48) +
                      zizj * g_53 + c00z * g_53 + b10 * g_52 + b00 * g_49;
        double g_64 = b01 * g_48 + c0pz * g_52 + zkzl * g_52;
        double g_65 = b00 * g_52 + b01 * g_49 + c0pz * g_53 + zkzl * g_53;
        double g_66 = zkzl * (zizj * g_52 + c0pz * g_49 + b00 * g_48) +
                      zizj * g_56 + c0pz * g_53 + b01 * g_49 + b00 * g_52;
        double g_67 =
            zkzl * (zizj * g_53 + c00z * g_53 + b10 * g_52 + b00 * g_49) +
            zizj * g_57 + c00z * g_57 + b10 * g_56 + 2 * b00 * g_53;
        double g_68 = 2 * b01 * g_52 + c0pz * g_56 + zkzl * g_56;
        double g_69 = 2 * b01 * g_53 + b00 * g_56 + c0pz * g_57 + zkzl * g_57;
        double g_70 =
            zkzl * (zizj * g_56 + c0pz * g_53 + b01 * g_49 + b00 * g_52) +
            zizj * (c0pz * g_56 + 2 * b01 * g_52) + c0pz * g_57 +
            2 * b01 * g_53 + b00 * g_56;
        double g_71 =
            zkzl * (zizj * g_57 + c00z * g_57 + b10 * g_56 + 2 * b00 * g_53) +
            zizj * (c0pz * g_57 + 2 * b01 * g_53 + b00 * g_56) +
            c00z * (c0pz * g_57 + 2 * b01 * g_53 + b00 * g_56) +
            b10 * (c0pz * g_56 + 2 * b01 * g_52) + 3 * b00 * g_57;
        gout0 += g_23 * g_24 * g_48;
        gout1 += g_22 * g_25 * g_48;
        gout2 += g_22 * g_24 * g_49;
        gout3 += g_21 * g_26 * g_48;
        gout4 += g_20 * g_27 * g_48;
        gout5 += g_20 * g_26 * g_49;
        gout6 += g_21 * g_24 * g_50;
        gout7 += g_20 * g_25 * g_50;
        gout8 += g_20 * g_24 * g_51;
        gout9 += g_19 * g_28 * g_48;
        gout10 += g_18 * g_29 * g_48;
        gout11 += g_18 * g_28 * g_49;
        gout12 += g_17 * g_30 * g_48;
        gout13 += g_16 * g_31 * g_48;
        gout14 += g_16 * g_30 * g_49;
        gout15 += g_17 * g_28 * g_50;
        gout16 += g_16 * g_29 * g_50;
        gout17 += g_16 * g_28 * g_51;
        gout18 += g_19 * g_24 * g_52;
        gout19 += g_18 * g_25 * g_52;
        gout20 += g_18 * g_24 * g_53;
        gout21 += g_17 * g_26 * g_52;
        gout22 += g_16 * g_27 * g_52;
        gout23 += g_16 * g_26 * g_53;
        gout24 += g_17 * g_24 * g_54;
        gout25 += g_16 * g_25 * g_54;
        gout26 += g_16 * g_24 * g_55;
        gout27 += g_15 * g_32 * g_48;
        gout28 += g_14 * g_33 * g_48;
        gout29 += g_14 * g_32 * g_49;
        gout30 += g_13 * g_34 * g_48;
        gout31 += g_12 * g_35 * g_48;
        gout32 += g_12 * g_34 * g_49;
        gout33 += g_13 * g_32 * g_50;
        gout34 += g_12 * g_33 * g_50;
        gout35 += g_12 * g_32 * g_51;
        gout36 += g_15 * g_28 * g_52;
        gout37 += g_14 * g_29 * g_52;
        gout38 += g_14 * g_28 * g_53;
        gout39 += g_13 * g_30 * g_52;
        gout40 += g_12 * g_31 * g_52;
        gout41 += g_12 * g_30 * g_53;
        gout42 += g_13 * g_28 * g_54;
        gout43 += g_12 * g_29 * g_54;
        gout44 += g_12 * g_28 * g_55;
        gout45 += g_15 * g_24 * g_56;
        gout46 += g_14 * g_25 * g_56;
        gout47 += g_14 * g_24 * g_57;
        gout48 += g_13 * g_26 * g_56;
        gout49 += g_12 * g_27 * g_56;
        gout50 += g_12 * g_26 * g_57;
        gout51 += g_13 * g_24 * g_58;
        gout52 += g_12 * g_25 * g_58;
        gout53 += g_12 * g_24 * g_59;
        gout54 += g_11 * g_36 * g_48;
        gout55 += g_10 * g_37 * g_48;
        gout56 += g_10 * g_36 * g_49;
        gout57 += g_9 * g_38 * g_48;
        gout58 += g_8 * g_39 * g_48;
        gout59 += g_8 * g_38 * g_49;
        gout60 += g_9 * g_36 * g_50;
        gout61 += g_8 * g_37 * g_50;
        gout62 += g_8 * g_36 * g_51;
        gout63 += g_7 * g_40 * g_48;
        gout64 += g_6 * g_41 * g_48;
        gout65 += g_6 * g_40 * g_49;
        gout66 += g_5 * g_42 * g_48;
        gout67 += g_4 * g_43 * g_48;
        gout68 += g_4 * g_42 * g_49;
        gout69 += g_5 * g_40 * g_50;
        gout70 += g_4 * g_41 * g_50;
        gout71 += g_4 * g_40 * g_51;
        gout72 += g_7 * g_36 * g_52;
        gout73 += g_6 * g_37 * g_52;
        gout74 += g_6 * g_36 * g_53;
        gout75 += g_5 * g_38 * g_52;
        gout76 += g_4 * g_39 * g_52;
        gout77 += g_4 * g_38 * g_53;
        gout78 += g_5 * g_36 * g_54;
        gout79 += g_4 * g_37 * g_54;
        gout80 += g_4 * g_36 * g_55;
        gout81 += g_3 * g_44 * g_48;
        gout82 += g_2 * g_45 * g_48;
        gout83 += g_2 * g_44 * g_49;
        gout84 += g_1 * g_46 * g_48;
        gout85 += g_0 * g_47 * g_48;
        gout86 += g_0 * g_46 * g_49;
        gout87 += g_1 * g_44 * g_50;
        gout88 += g_0 * g_45 * g_50;
        gout89 += g_0 * g_44 * g_51;
        gout90 += g_3 * g_40 * g_52;
        gout91 += g_2 * g_41 * g_52;
        gout92 += g_2 * g_40 * g_53;
        gout93 += g_1 * g_42 * g_52;
        gout94 += g_0 * g_43 * g_52;
        gout95 += g_0 * g_42 * g_53;
        gout96 += g_1 * g_40 * g_54;
        gout97 += g_0 * g_41 * g_54;
        gout98 += g_0 * g_40 * g_55;
        gout99 += g_3 * g_36 * g_56;
        gout100 += g_2 * g_37 * g_56;
        gout101 += g_2 * g_36 * g_57;
        gout102 += g_1 * g_38 * g_56;
        gout103 += g_0 * g_39 * g_56;
        gout104 += g_0 * g_38 * g_57;
        gout105 += g_1 * g_36 * g_58;
        gout106 += g_0 * g_37 * g_58;
        gout107 += g_0 * g_36 * g_59;
        gout108 += g_11 * g_24 * g_60;
        gout109 += g_10 * g_25 * g_60;
        gout110 += g_10 * g_24 * g_61;
        gout111 += g_9 * g_26 * g_60;
        gout112 += g_8 * g_27 * g_60;
        gout113 += g_8 * g_26 * g_61;
        gout114 += g_9 * g_24 * g_62;
        gout115 += g_8 * g_25 * g_62;
        gout116 += g_8 * g_24 * g_63;
        gout117 += g_7 * g_28 * g_60;
        gout118 += g_6 * g_29 * g_60;
        gout119 += g_6 * g_28 * g_61;
        gout120 += g_5 * g_30 * g_60;
        gout121 += g_4 * g_31 * g_60;
        gout122 += g_4 * g_30 * g_61;
        gout123 += g_5 * g_28 * g_62;
        gout124 += g_4 * g_29 * g_62;
        gout125 += g_4 * g_28 * g_63;
        gout126 += g_7 * g_24 * g_64;
        gout127 += g_6 * g_25 * g_64;
        gout128 += g_6 * g_24 * g_65;
        gout129 += g_5 * g_26 * g_64;
        gout130 += g_4 * g_27 * g_64;
        gout131 += g_4 * g_26 * g_65;
        gout132 += g_5 * g_24 * g_66;
        gout133 += g_4 * g_25 * g_66;
        gout134 += g_4 * g_24 * g_67;
        gout135 += g_3 * g_32 * g_60;
        gout136 += g_2 * g_33 * g_60;
        gout137 += g_2 * g_32 * g_61;
        gout138 += g_1 * g_34 * g_60;
        gout139 += g_0 * g_35 * g_60;
        gout140 += g_0 * g_34 * g_61;
        gout141 += g_1 * g_32 * g_62;
        gout142 += g_0 * g_33 * g_62;
        gout143 += g_0 * g_32 * g_63;
        gout144 += g_3 * g_28 * g_64;
        gout145 += g_2 * g_29 * g_64;
        gout146 += g_2 * g_28 * g_65;
        gout147 += g_1 * g_30 * g_64;
        gout148 += g_0 * g_31 * g_64;
        gout149 += g_0 * g_30 * g_65;
        gout150 += g_1 * g_28 * g_66;
        gout151 += g_0 * g_29 * g_66;
        gout152 += g_0 * g_28 * g_67;
        gout153 += g_3 * g_24 * g_68;
        gout154 += g_2 * g_25 * g_68;
        gout155 += g_2 * g_24 * g_69;
        gout156 += g_1 * g_26 * g_68;
        gout157 += g_0 * g_27 * g_68;
        gout158 += g_0 * g_26 * g_69;
        gout159 += g_1 * g_24 * g_70;
        gout160 += g_0 * g_25 * g_70;
        gout161 += g_0 * g_24 * g_71;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        gout81 = reduce(gout81);
        gout82 = reduce(gout82);
        gout83 = reduce(gout83);
        gout84 = reduce(gout84);
        gout85 = reduce(gout85);
        gout86 = reduce(gout86);
        gout87 = reduce(gout87);
        gout88 = reduce(gout88);
        gout89 = reduce(gout89);
        gout90 = reduce(gout90);
        gout91 = reduce(gout91);
        gout92 = reduce(gout92);
        gout93 = reduce(gout93);
        gout94 = reduce(gout94);
        gout95 = reduce(gout95);
        gout96 = reduce(gout96);
        gout97 = reduce(gout97);
        gout98 = reduce(gout98);
        gout99 = reduce(gout99);
        gout100 = reduce(gout100);
        gout101 = reduce(gout101);
        gout102 = reduce(gout102);
        gout103 = reduce(gout103);
        gout104 = reduce(gout104);
        gout105 = reduce(gout105);
        gout106 = reduce(gout106);
        gout107 = reduce(gout107);
        gout108 = reduce(gout108);
        gout109 = reduce(gout109);
        gout110 = reduce(gout110);
        gout111 = reduce(gout111);
        gout112 = reduce(gout112);
        gout113 = reduce(gout113);
        gout114 = reduce(gout114);
        gout115 = reduce(gout115);
        gout116 = reduce(gout116);
        gout117 = reduce(gout117);
        gout118 = reduce(gout118);
        gout119 = reduce(gout119);
        gout120 = reduce(gout120);
        gout121 = reduce(gout121);
        gout122 = reduce(gout122);
        gout123 = reduce(gout123);
        gout124 = reduce(gout124);
        gout125 = reduce(gout125);
        gout126 = reduce(gout126);
        gout127 = reduce(gout127);
        gout128 = reduce(gout128);
        gout129 = reduce(gout129);
        gout130 = reduce(gout130);
        gout131 = reduce(gout131);
        gout132 = reduce(gout132);
        gout133 = reduce(gout133);
        gout134 = reduce(gout134);
        gout135 = reduce(gout135);
        gout136 = reduce(gout136);
        gout137 = reduce(gout137);
        gout138 = reduce(gout138);
        gout139 = reduce(gout139);
        gout140 = reduce(gout140);
        gout141 = reduce(gout141);
        gout142 = reduce(gout142);
        gout143 = reduce(gout143);
        gout144 = reduce(gout144);
        gout145 = reduce(gout145);
        gout146 = reduce(gout146);
        gout147 = reduce(gout147);
        gout148 = reduce(gout148);
        gout149 = reduce(gout149);
        gout150 = reduce(gout150);
        gout151 = reduce(gout151);
        gout152 = reduce(gout152);
        gout153 = reduce(gout153);
        gout154 = reduce(gout154);
        gout155 = reduce(gout155);
        gout156 = reduce(gout156);
        gout157 = reduce(gout157);
        gout158 = reduce(gout158);
        gout159 = reduce(gout159);
        gout160 = reduce(gout160);
        gout161 = reduce(gout161);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 1 * jstride, gout3);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout4);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout5);
    atomicAdd(peri + 2 * jstride, gout6);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout7);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout8);
    atomicAdd(peri + 1 * kstride, gout9);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout10);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 1 * jstride + 1 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * kstride, gout14);
    atomicAdd(peri + 2 * jstride + 1 * kstride, gout15);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * kstride, gout16);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * kstride, gout17);
    atomicAdd(peri + 2 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout20);
    atomicAdd(peri + 1 * jstride + 2 * kstride, gout21);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * kstride, gout22);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * kstride, gout23);
    atomicAdd(peri + 2 * jstride + 2 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * kstride, gout26);
    atomicAdd(peri + 3 * kstride, gout27);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout28);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout29);
    atomicAdd(peri + 1 * jstride + 3 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 1 * jstride + 3 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 1 * jstride + 3 * kstride, gout32);
    atomicAdd(peri + 2 * jstride + 3 * kstride, gout33);
    atomicAdd(peri + 1 * istride + 2 * jstride + 3 * kstride, gout34);
    atomicAdd(peri + 2 * istride + 2 * jstride + 3 * kstride, gout35);
    atomicAdd(peri + 4 * kstride, gout36);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout37);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout38);
    atomicAdd(peri + 1 * jstride + 4 * kstride, gout39);
    atomicAdd(peri + 1 * istride + 1 * jstride + 4 * kstride, gout40);
    atomicAdd(peri + 2 * istride + 1 * jstride + 4 * kstride, gout41);
    atomicAdd(peri + 2 * jstride + 4 * kstride, gout42);
    atomicAdd(peri + 1 * istride + 2 * jstride + 4 * kstride, gout43);
    atomicAdd(peri + 2 * istride + 2 * jstride + 4 * kstride, gout44);
    atomicAdd(peri + 5 * kstride, gout45);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout46);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout47);
    atomicAdd(peri + 1 * jstride + 5 * kstride, gout48);
    atomicAdd(peri + 1 * istride + 1 * jstride + 5 * kstride, gout49);
    atomicAdd(peri + 2 * istride + 1 * jstride + 5 * kstride, gout50);
    atomicAdd(peri + 2 * jstride + 5 * kstride, gout51);
    atomicAdd(peri + 1 * istride + 2 * jstride + 5 * kstride, gout52);
    atomicAdd(peri + 2 * istride + 2 * jstride + 5 * kstride, gout53);
    atomicAdd(peri + 1 * lstride, gout54);
    atomicAdd(peri + 1 * istride + 1 * lstride, gout55);
    atomicAdd(peri + 2 * istride + 1 * lstride, gout56);
    atomicAdd(peri + 1 * jstride + 1 * lstride, gout57);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * lstride, gout58);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * lstride, gout59);
    atomicAdd(peri + 2 * jstride + 1 * lstride, gout60);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * lstride, gout61);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * lstride, gout62);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout63);
    atomicAdd(peri + 1 * istride + 1 * kstride + 1 * lstride, gout64);
    atomicAdd(peri + 2 * istride + 1 * kstride + 1 * lstride, gout65);
    atomicAdd(peri + 1 * jstride + 1 * kstride + 1 * lstride, gout66);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 1 * kstride + 1 * lstride, gout67);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 1 * kstride + 1 * lstride, gout68);
    atomicAdd(peri + 2 * jstride + 1 * kstride + 1 * lstride, gout69);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 1 * kstride + 1 * lstride, gout70);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 1 * kstride + 1 * lstride, gout71);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout72);
    atomicAdd(peri + 1 * istride + 2 * kstride + 1 * lstride, gout73);
    atomicAdd(peri + 2 * istride + 2 * kstride + 1 * lstride, gout74);
    atomicAdd(peri + 1 * jstride + 2 * kstride + 1 * lstride, gout75);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 2 * kstride + 1 * lstride, gout76);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 2 * kstride + 1 * lstride, gout77);
    atomicAdd(peri + 2 * jstride + 2 * kstride + 1 * lstride, gout78);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 2 * kstride + 1 * lstride, gout79);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 2 * kstride + 1 * lstride, gout80);
    atomicAdd(peri + 3 * kstride + 1 * lstride, gout81);
    atomicAdd(peri + 1 * istride + 3 * kstride + 1 * lstride, gout82);
    atomicAdd(peri + 2 * istride + 3 * kstride + 1 * lstride, gout83);
    atomicAdd(peri + 1 * jstride + 3 * kstride + 1 * lstride, gout84);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 3 * kstride + 1 * lstride, gout85);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 3 * kstride + 1 * lstride, gout86);
    atomicAdd(peri + 2 * jstride + 3 * kstride + 1 * lstride, gout87);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 3 * kstride + 1 * lstride, gout88);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 3 * kstride + 1 * lstride, gout89);
    atomicAdd(peri + 4 * kstride + 1 * lstride, gout90);
    atomicAdd(peri + 1 * istride + 4 * kstride + 1 * lstride, gout91);
    atomicAdd(peri + 2 * istride + 4 * kstride + 1 * lstride, gout92);
    atomicAdd(peri + 1 * jstride + 4 * kstride + 1 * lstride, gout93);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 4 * kstride + 1 * lstride, gout94);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 4 * kstride + 1 * lstride, gout95);
    atomicAdd(peri + 2 * jstride + 4 * kstride + 1 * lstride, gout96);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 4 * kstride + 1 * lstride, gout97);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 4 * kstride + 1 * lstride, gout98);
    atomicAdd(peri + 5 * kstride + 1 * lstride, gout99);
    atomicAdd(peri + 1 * istride + 5 * kstride + 1 * lstride, gout100);
    atomicAdd(peri + 2 * istride + 5 * kstride + 1 * lstride, gout101);
    atomicAdd(peri + 1 * jstride + 5 * kstride + 1 * lstride, gout102);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 5 * kstride + 1 * lstride, gout103);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 5 * kstride + 1 * lstride, gout104);
    atomicAdd(peri + 2 * jstride + 5 * kstride + 1 * lstride, gout105);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 5 * kstride + 1 * lstride, gout106);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 5 * kstride + 1 * lstride, gout107);
    atomicAdd(peri + 2 * lstride, gout108);
    atomicAdd(peri + 1 * istride + 2 * lstride, gout109);
    atomicAdd(peri + 2 * istride + 2 * lstride, gout110);
    atomicAdd(peri + 1 * jstride + 2 * lstride, gout111);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * lstride, gout112);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * lstride, gout113);
    atomicAdd(peri + 2 * jstride + 2 * lstride, gout114);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * lstride, gout115);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * lstride, gout116);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout117);
    atomicAdd(peri + 1 * istride + 1 * kstride + 2 * lstride, gout118);
    atomicAdd(peri + 2 * istride + 1 * kstride + 2 * lstride, gout119);
    atomicAdd(peri + 1 * jstride + 1 * kstride + 2 * lstride, gout120);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 1 * kstride + 2 * lstride, gout121);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 1 * kstride + 2 * lstride, gout122);
    atomicAdd(peri + 2 * jstride + 1 * kstride + 2 * lstride, gout123);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 1 * kstride + 2 * lstride, gout124);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 1 * kstride + 2 * lstride, gout125);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout126);
    atomicAdd(peri + 1 * istride + 2 * kstride + 2 * lstride, gout127);
    atomicAdd(peri + 2 * istride + 2 * kstride + 2 * lstride, gout128);
    atomicAdd(peri + 1 * jstride + 2 * kstride + 2 * lstride, gout129);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 2 * kstride + 2 * lstride, gout130);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 2 * kstride + 2 * lstride, gout131);
    atomicAdd(peri + 2 * jstride + 2 * kstride + 2 * lstride, gout132);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 2 * kstride + 2 * lstride, gout133);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 2 * kstride + 2 * lstride, gout134);
    atomicAdd(peri + 3 * kstride + 2 * lstride, gout135);
    atomicAdd(peri + 1 * istride + 3 * kstride + 2 * lstride, gout136);
    atomicAdd(peri + 2 * istride + 3 * kstride + 2 * lstride, gout137);
    atomicAdd(peri + 1 * jstride + 3 * kstride + 2 * lstride, gout138);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 3 * kstride + 2 * lstride, gout139);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 3 * kstride + 2 * lstride, gout140);
    atomicAdd(peri + 2 * jstride + 3 * kstride + 2 * lstride, gout141);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 3 * kstride + 2 * lstride, gout142);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 3 * kstride + 2 * lstride, gout143);
    atomicAdd(peri + 4 * kstride + 2 * lstride, gout144);
    atomicAdd(peri + 1 * istride + 4 * kstride + 2 * lstride, gout145);
    atomicAdd(peri + 2 * istride + 4 * kstride + 2 * lstride, gout146);
    atomicAdd(peri + 1 * jstride + 4 * kstride + 2 * lstride, gout147);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 4 * kstride + 2 * lstride, gout148);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 4 * kstride + 2 * lstride, gout149);
    atomicAdd(peri + 2 * jstride + 4 * kstride + 2 * lstride, gout150);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 4 * kstride + 2 * lstride, gout151);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 4 * kstride + 2 * lstride, gout152);
    atomicAdd(peri + 5 * kstride + 2 * lstride, gout153);
    atomicAdd(peri + 1 * istride + 5 * kstride + 2 * lstride, gout154);
    atomicAdd(peri + 2 * istride + 5 * kstride + 2 * lstride, gout155);
    atomicAdd(peri + 1 * jstride + 5 * kstride + 2 * lstride, gout156);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 5 * kstride + 2 * lstride, gout157);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 5 * kstride + 2 * lstride, gout158);
    atomicAdd(peri + 2 * jstride + 5 * kstride + 2 * lstride, gout159);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 5 * kstride + 2 * lstride, gout160);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 5 * kstride + 2 * lstride, gout161);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel1130(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x + xixj;
        double g_3 = c00x * (c00x + xixj) + b10;
        double g_4 = c0px;
        double g_5 = c0px * c00x + b00;
        double g_6 = c0px * (c00x + xixj) + b00;
        double g_7 = b00 * c00x + b10 * c0px + c00x * g_5 + xixj * g_5;
        double g_8 = c0px * c0px + b01;
        double g_9 = b00 * c0px + b01 * c00x + c0px * g_5;
        double g_10 = b00 * c0px + b01 * c00x + c0px * g_5 + xixj * g_8;
        double g_11 = 2 * b00 * g_5 + b10 * g_8 + c00x * g_9 + xixj * g_9;
        double g_12 = c0px * (2 * b01 + g_8);
        double g_13 = 2 * b01 * g_5 + b00 * g_8 + c0px * g_9;
        double g_14 = 2 * b01 * g_5 + b00 * g_8 + c0px * g_9 + xixj * g_12;
        double g_15 = 3 * b00 * g_9 + b10 * g_12 + c00x * g_13 + xixj * g_13;
        double g_16 = 1;
        double g_17 = c00y;
        double g_18 = c00y + yiyj;
        double g_19 = c00y * (c00y + yiyj) + b10;
        double g_20 = c0py;
        double g_21 = c0py * c00y + b00;
        double g_22 = c0py * (c00y + yiyj) + b00;
        double g_23 = b00 * c00y + b10 * c0py + c00y * g_21 + yiyj * g_21;
        double g_24 = c0py * c0py + b01;
        double g_25 = b00 * c0py + b01 * c00y + c0py * g_21;
        double g_26 = b00 * c0py + b01 * c00y + c0py * g_21 + yiyj * g_24;
        double g_27 = 2 * b00 * g_21 + b10 * g_24 + c00y * g_25 + yiyj * g_25;
        double g_28 = c0py * (2 * b01 + g_24);
        double g_29 = 2 * b01 * g_21 + b00 * g_24 + c0py * g_25;
        double g_30 = 2 * b01 * g_21 + b00 * g_24 + c0py * g_25 + yiyj * g_28;
        double g_31 = 3 * b00 * g_25 + b10 * g_28 + c00y * g_29 + yiyj * g_29;
        double g_32 = weight0 * fac;
        double g_33 = c00z * g_32;
        double g_34 = g_32 * (c00z + zizj);
        double g_35 = b10 * g_32 + c00z * g_33 + zizj * g_33;
        double g_36 = c0pz * g_32;
        double g_37 = b00 * g_32 + c0pz * g_33;
        double g_38 = b00 * g_32 + c0pz * g_33 + zizj * g_36;
        double g_39 = b00 * g_33 + b10 * g_36 + c00z * g_37 + zizj * g_37;
        double g_40 = b01 * g_32 + c0pz * g_36;
        double g_41 = b00 * g_36 + b01 * g_33 + c0pz * g_37;
        double g_42 = b00 * g_36 + b01 * g_33 + c0pz * g_37 + zizj * g_40;
        double g_43 = 2 * b00 * g_37 + b10 * g_40 + c00z * g_41 + zizj * g_41;
        double g_44 = 2 * b01 * g_36 + c0pz * g_40;
        double g_45 = 2 * b01 * g_37 + b00 * g_40 + c0pz * g_41;
        double g_46 = 2 * b01 * g_37 + b00 * g_40 + c0pz * g_41 + zizj * g_44;
        double g_47 = 3 * b00 * g_41 + b10 * g_44 + c00z * g_45 + zizj * g_45;
        gout0 += g_15 * g_16 * g_32;
        gout1 += g_14 * g_17 * g_32;
        gout2 += g_14 * g_16 * g_33;
        gout3 += g_13 * g_18 * g_32;
        gout4 += g_12 * g_19 * g_32;
        gout5 += g_12 * g_18 * g_33;
        gout6 += g_13 * g_16 * g_34;
        gout7 += g_12 * g_17 * g_34;
        gout8 += g_12 * g_16 * g_35;
        gout9 += g_11 * g_20 * g_32;
        gout10 += g_10 * g_21 * g_32;
        gout11 += g_10 * g_20 * g_33;
        gout12 += g_9 * g_22 * g_32;
        gout13 += g_8 * g_23 * g_32;
        gout14 += g_8 * g_22 * g_33;
        gout15 += g_9 * g_20 * g_34;
        gout16 += g_8 * g_21 * g_34;
        gout17 += g_8 * g_20 * g_35;
        gout18 += g_11 * g_16 * g_36;
        gout19 += g_10 * g_17 * g_36;
        gout20 += g_10 * g_16 * g_37;
        gout21 += g_9 * g_18 * g_36;
        gout22 += g_8 * g_19 * g_36;
        gout23 += g_8 * g_18 * g_37;
        gout24 += g_9 * g_16 * g_38;
        gout25 += g_8 * g_17 * g_38;
        gout26 += g_8 * g_16 * g_39;
        gout27 += g_7 * g_24 * g_32;
        gout28 += g_6 * g_25 * g_32;
        gout29 += g_6 * g_24 * g_33;
        gout30 += g_5 * g_26 * g_32;
        gout31 += g_4 * g_27 * g_32;
        gout32 += g_4 * g_26 * g_33;
        gout33 += g_5 * g_24 * g_34;
        gout34 += g_4 * g_25 * g_34;
        gout35 += g_4 * g_24 * g_35;
        gout36 += g_7 * g_20 * g_36;
        gout37 += g_6 * g_21 * g_36;
        gout38 += g_6 * g_20 * g_37;
        gout39 += g_5 * g_22 * g_36;
        gout40 += g_4 * g_23 * g_36;
        gout41 += g_4 * g_22 * g_37;
        gout42 += g_5 * g_20 * g_38;
        gout43 += g_4 * g_21 * g_38;
        gout44 += g_4 * g_20 * g_39;
        gout45 += g_7 * g_16 * g_40;
        gout46 += g_6 * g_17 * g_40;
        gout47 += g_6 * g_16 * g_41;
        gout48 += g_5 * g_18 * g_40;
        gout49 += g_4 * g_19 * g_40;
        gout50 += g_4 * g_18 * g_41;
        gout51 += g_5 * g_16 * g_42;
        gout52 += g_4 * g_17 * g_42;
        gout53 += g_4 * g_16 * g_43;
        gout54 += g_3 * g_28 * g_32;
        gout55 += g_2 * g_29 * g_32;
        gout56 += g_2 * g_28 * g_33;
        gout57 += g_1 * g_30 * g_32;
        gout58 += g_0 * g_31 * g_32;
        gout59 += g_0 * g_30 * g_33;
        gout60 += g_1 * g_28 * g_34;
        gout61 += g_0 * g_29 * g_34;
        gout62 += g_0 * g_28 * g_35;
        gout63 += g_3 * g_24 * g_36;
        gout64 += g_2 * g_25 * g_36;
        gout65 += g_2 * g_24 * g_37;
        gout66 += g_1 * g_26 * g_36;
        gout67 += g_0 * g_27 * g_36;
        gout68 += g_0 * g_26 * g_37;
        gout69 += g_1 * g_24 * g_38;
        gout70 += g_0 * g_25 * g_38;
        gout71 += g_0 * g_24 * g_39;
        gout72 += g_3 * g_20 * g_40;
        gout73 += g_2 * g_21 * g_40;
        gout74 += g_2 * g_20 * g_41;
        gout75 += g_1 * g_22 * g_40;
        gout76 += g_0 * g_23 * g_40;
        gout77 += g_0 * g_22 * g_41;
        gout78 += g_1 * g_20 * g_42;
        gout79 += g_0 * g_21 * g_42;
        gout80 += g_0 * g_20 * g_43;
        gout81 += g_3 * g_16 * g_44;
        gout82 += g_2 * g_17 * g_44;
        gout83 += g_2 * g_16 * g_45;
        gout84 += g_1 * g_18 * g_44;
        gout85 += g_0 * g_19 * g_44;
        gout86 += g_0 * g_18 * g_45;
        gout87 += g_1 * g_16 * g_46;
        gout88 += g_0 * g_17 * g_46;
        gout89 += g_0 * g_16 * g_47;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        gout81 = reduce(gout81);
        gout82 = reduce(gout82);
        gout83 = reduce(gout83);
        gout84 = reduce(gout84);
        gout85 = reduce(gout85);
        gout86 = reduce(gout86);
        gout87 = reduce(gout87);
        gout88 = reduce(gout88);
        gout89 = reduce(gout89);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 1 * jstride, gout3);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout4);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout5);
    atomicAdd(peri + 2 * jstride, gout6);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout7);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout8);
    atomicAdd(peri + 1 * kstride, gout9);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout10);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 1 * jstride + 1 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * kstride, gout14);
    atomicAdd(peri + 2 * jstride + 1 * kstride, gout15);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * kstride, gout16);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * kstride, gout17);
    atomicAdd(peri + 2 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout20);
    atomicAdd(peri + 1 * jstride + 2 * kstride, gout21);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * kstride, gout22);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * kstride, gout23);
    atomicAdd(peri + 2 * jstride + 2 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * kstride, gout26);
    atomicAdd(peri + 3 * kstride, gout27);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout28);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout29);
    atomicAdd(peri + 1 * jstride + 3 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 1 * jstride + 3 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 1 * jstride + 3 * kstride, gout32);
    atomicAdd(peri + 2 * jstride + 3 * kstride, gout33);
    atomicAdd(peri + 1 * istride + 2 * jstride + 3 * kstride, gout34);
    atomicAdd(peri + 2 * istride + 2 * jstride + 3 * kstride, gout35);
    atomicAdd(peri + 4 * kstride, gout36);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout37);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout38);
    atomicAdd(peri + 1 * jstride + 4 * kstride, gout39);
    atomicAdd(peri + 1 * istride + 1 * jstride + 4 * kstride, gout40);
    atomicAdd(peri + 2 * istride + 1 * jstride + 4 * kstride, gout41);
    atomicAdd(peri + 2 * jstride + 4 * kstride, gout42);
    atomicAdd(peri + 1 * istride + 2 * jstride + 4 * kstride, gout43);
    atomicAdd(peri + 2 * istride + 2 * jstride + 4 * kstride, gout44);
    atomicAdd(peri + 5 * kstride, gout45);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout46);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout47);
    atomicAdd(peri + 1 * jstride + 5 * kstride, gout48);
    atomicAdd(peri + 1 * istride + 1 * jstride + 5 * kstride, gout49);
    atomicAdd(peri + 2 * istride + 1 * jstride + 5 * kstride, gout50);
    atomicAdd(peri + 2 * jstride + 5 * kstride, gout51);
    atomicAdd(peri + 1 * istride + 2 * jstride + 5 * kstride, gout52);
    atomicAdd(peri + 2 * istride + 2 * jstride + 5 * kstride, gout53);
    atomicAdd(peri + 6 * kstride, gout54);
    atomicAdd(peri + 1 * istride + 6 * kstride, gout55);
    atomicAdd(peri + 2 * istride + 6 * kstride, gout56);
    atomicAdd(peri + 1 * jstride + 6 * kstride, gout57);
    atomicAdd(peri + 1 * istride + 1 * jstride + 6 * kstride, gout58);
    atomicAdd(peri + 2 * istride + 1 * jstride + 6 * kstride, gout59);
    atomicAdd(peri + 2 * jstride + 6 * kstride, gout60);
    atomicAdd(peri + 1 * istride + 2 * jstride + 6 * kstride, gout61);
    atomicAdd(peri + 2 * istride + 2 * jstride + 6 * kstride, gout62);
    atomicAdd(peri + 7 * kstride, gout63);
    atomicAdd(peri + 1 * istride + 7 * kstride, gout64);
    atomicAdd(peri + 2 * istride + 7 * kstride, gout65);
    atomicAdd(peri + 1 * jstride + 7 * kstride, gout66);
    atomicAdd(peri + 1 * istride + 1 * jstride + 7 * kstride, gout67);
    atomicAdd(peri + 2 * istride + 1 * jstride + 7 * kstride, gout68);
    atomicAdd(peri + 2 * jstride + 7 * kstride, gout69);
    atomicAdd(peri + 1 * istride + 2 * jstride + 7 * kstride, gout70);
    atomicAdd(peri + 2 * istride + 2 * jstride + 7 * kstride, gout71);
    atomicAdd(peri + 8 * kstride, gout72);
    atomicAdd(peri + 1 * istride + 8 * kstride, gout73);
    atomicAdd(peri + 2 * istride + 8 * kstride, gout74);
    atomicAdd(peri + 1 * jstride + 8 * kstride, gout75);
    atomicAdd(peri + 1 * istride + 1 * jstride + 8 * kstride, gout76);
    atomicAdd(peri + 2 * istride + 1 * jstride + 8 * kstride, gout77);
    atomicAdd(peri + 2 * jstride + 8 * kstride, gout78);
    atomicAdd(peri + 1 * istride + 2 * jstride + 8 * kstride, gout79);
    atomicAdd(peri + 2 * istride + 2 * jstride + 8 * kstride, gout80);
    atomicAdd(peri + 9 * kstride, gout81);
    atomicAdd(peri + 1 * istride + 9 * kstride, gout82);
    atomicAdd(peri + 2 * istride + 9 * kstride, gout83);
    atomicAdd(peri + 1 * jstride + 9 * kstride, gout84);
    atomicAdd(peri + 1 * istride + 1 * jstride + 9 * kstride, gout85);
    atomicAdd(peri + 2 * istride + 1 * jstride + 9 * kstride, gout86);
    atomicAdd(peri + 2 * jstride + 9 * kstride, gout87);
    atomicAdd(peri + 1 * istride + 2 * jstride + 9 * kstride, gout88);
    atomicAdd(peri + 2 * istride + 2 * jstride + 9 * kstride, gout89);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel2011(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c0px;
        double g_4 = c0px * c00x + b00;
        double g_5 = b00 * c00x + b10 * c0px + c00x * g_4;
        double g_6 = c0px + xkxl;
        double g_7 = c00x * (c0px + xkxl) + b00;
        double g_8 = b00 * c00x + b10 * c0px + c00x * g_4 + xkxl * g_2;
        double g_9 = c0px * (c0px + xkxl) + b01;
        double g_10 = b00 * c0px + b01 * c00x + c0px * g_4 + xkxl * g_4;
        double g_11 = xkxl * g_5 +
                      c00x * (c0px * g_4 + b01 * c00x + b00 * c0px) +
                      b10 * (c0px * c0px + b01) + 2 * b00 * g_4;
        double g_12 = 1;
        double g_13 = c00y;
        double g_14 = c00y * c00y + b10;
        double g_15 = c0py;
        double g_16 = c0py * c00y + b00;
        double g_17 = b00 * c00y + b10 * c0py + c00y * g_16;
        double g_18 = c0py + ykyl;
        double g_19 = c00y * (c0py + ykyl) + b00;
        double g_20 = b00 * c00y + b10 * c0py + c00y * g_16 + ykyl * g_14;
        double g_21 = c0py * (c0py + ykyl) + b01;
        double g_22 = b00 * c0py + b01 * c00y + c0py * g_16 + ykyl * g_16;
        double g_23 = ykyl * g_17 +
                      c00y * (c0py * g_16 + b01 * c00y + b00 * c0py) +
                      b10 * (c0py * c0py + b01) + 2 * b00 * g_16;
        double g_24 = weight0 * fac;
        double g_25 = c00z * g_24;
        double g_26 = b10 * g_24 + c00z * g_25;
        double g_27 = c0pz * g_24;
        double g_28 = b00 * g_24 + c0pz * g_25;
        double g_29 = b00 * g_25 + b10 * g_27 + c00z * g_28;
        double g_30 = g_24 * (c0pz + zkzl);
        double g_31 = b00 * g_24 + c0pz * g_25 + zkzl * g_25;
        double g_32 = b00 * g_25 + b10 * g_27 + c00z * g_28 + zkzl * g_26;
        double g_33 = b01 * g_24 + c0pz * g_27 + zkzl * g_27;
        double g_34 = b00 * g_27 + b01 * g_25 + c0pz * g_28 + zkzl * g_28;
        double g_35 = zkzl * g_29 +
                      c00z * (c0pz * g_28 + b01 * g_25 + b00 * g_27) +
                      b10 * (c0pz * g_27 + b01 * g_24) + 2 * b00 * g_28;
        gout0 += g_11 * g_12 * g_24;
        gout1 += g_10 * g_13 * g_24;
        gout2 += g_10 * g_12 * g_25;
        gout3 += g_9 * g_14 * g_24;
        gout4 += g_9 * g_13 * g_25;
        gout5 += g_9 * g_12 * g_26;
        gout6 += g_8 * g_15 * g_24;
        gout7 += g_7 * g_16 * g_24;
        gout8 += g_7 * g_15 * g_25;
        gout9 += g_6 * g_17 * g_24;
        gout10 += g_6 * g_16 * g_25;
        gout11 += g_6 * g_15 * g_26;
        gout12 += g_8 * g_12 * g_27;
        gout13 += g_7 * g_13 * g_27;
        gout14 += g_7 * g_12 * g_28;
        gout15 += g_6 * g_14 * g_27;
        gout16 += g_6 * g_13 * g_28;
        gout17 += g_6 * g_12 * g_29;
        gout18 += g_5 * g_18 * g_24;
        gout19 += g_4 * g_19 * g_24;
        gout20 += g_4 * g_18 * g_25;
        gout21 += g_3 * g_20 * g_24;
        gout22 += g_3 * g_19 * g_25;
        gout23 += g_3 * g_18 * g_26;
        gout24 += g_2 * g_21 * g_24;
        gout25 += g_1 * g_22 * g_24;
        gout26 += g_1 * g_21 * g_25;
        gout27 += g_0 * g_23 * g_24;
        gout28 += g_0 * g_22 * g_25;
        gout29 += g_0 * g_21 * g_26;
        gout30 += g_2 * g_18 * g_27;
        gout31 += g_1 * g_19 * g_27;
        gout32 += g_1 * g_18 * g_28;
        gout33 += g_0 * g_20 * g_27;
        gout34 += g_0 * g_19 * g_28;
        gout35 += g_0 * g_18 * g_29;
        gout36 += g_5 * g_12 * g_30;
        gout37 += g_4 * g_13 * g_30;
        gout38 += g_4 * g_12 * g_31;
        gout39 += g_3 * g_14 * g_30;
        gout40 += g_3 * g_13 * g_31;
        gout41 += g_3 * g_12 * g_32;
        gout42 += g_2 * g_15 * g_30;
        gout43 += g_1 * g_16 * g_30;
        gout44 += g_1 * g_15 * g_31;
        gout45 += g_0 * g_17 * g_30;
        gout46 += g_0 * g_16 * g_31;
        gout47 += g_0 * g_15 * g_32;
        gout48 += g_2 * g_12 * g_33;
        gout49 += g_1 * g_13 * g_33;
        gout50 += g_1 * g_12 * g_34;
        gout51 += g_0 * g_14 * g_33;
        gout52 += g_0 * g_13 * g_34;
        gout53 += g_0 * g_12 * g_35;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 1 * kstride, gout6);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout7);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout8);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout9);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout10);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 2 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout14);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout15);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout16);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout17);
    atomicAdd(peri + 1 * lstride, gout18);
    atomicAdd(peri + 1 * istride + 1 * lstride, gout19);
    atomicAdd(peri + 2 * istride + 1 * lstride, gout20);
    atomicAdd(peri + 3 * istride + 1 * lstride, gout21);
    atomicAdd(peri + 4 * istride + 1 * lstride, gout22);
    atomicAdd(peri + 5 * istride + 1 * lstride, gout23);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout24);
    atomicAdd(peri + 1 * istride + 1 * kstride + 1 * lstride, gout25);
    atomicAdd(peri + 2 * istride + 1 * kstride + 1 * lstride, gout26);
    atomicAdd(peri + 3 * istride + 1 * kstride + 1 * lstride, gout27);
    atomicAdd(peri + 4 * istride + 1 * kstride + 1 * lstride, gout28);
    atomicAdd(peri + 5 * istride + 1 * kstride + 1 * lstride, gout29);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout30);
    atomicAdd(peri + 1 * istride + 2 * kstride + 1 * lstride, gout31);
    atomicAdd(peri + 2 * istride + 2 * kstride + 1 * lstride, gout32);
    atomicAdd(peri + 3 * istride + 2 * kstride + 1 * lstride, gout33);
    atomicAdd(peri + 4 * istride + 2 * kstride + 1 * lstride, gout34);
    atomicAdd(peri + 5 * istride + 2 * kstride + 1 * lstride, gout35);
    atomicAdd(peri + 2 * lstride, gout36);
    atomicAdd(peri + 1 * istride + 2 * lstride, gout37);
    atomicAdd(peri + 2 * istride + 2 * lstride, gout38);
    atomicAdd(peri + 3 * istride + 2 * lstride, gout39);
    atomicAdd(peri + 4 * istride + 2 * lstride, gout40);
    atomicAdd(peri + 5 * istride + 2 * lstride, gout41);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout42);
    atomicAdd(peri + 1 * istride + 1 * kstride + 2 * lstride, gout43);
    atomicAdd(peri + 2 * istride + 1 * kstride + 2 * lstride, gout44);
    atomicAdd(peri + 3 * istride + 1 * kstride + 2 * lstride, gout45);
    atomicAdd(peri + 4 * istride + 1 * kstride + 2 * lstride, gout46);
    atomicAdd(peri + 5 * istride + 1 * kstride + 2 * lstride, gout47);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout48);
    atomicAdd(peri + 1 * istride + 2 * kstride + 2 * lstride, gout49);
    atomicAdd(peri + 2 * istride + 2 * kstride + 2 * lstride, gout50);
    atomicAdd(peri + 3 * istride + 2 * kstride + 2 * lstride, gout51);
    atomicAdd(peri + 4 * istride + 2 * kstride + 2 * lstride, gout52);
    atomicAdd(peri + 5 * istride + 2 * kstride + 2 * lstride, gout53);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel2020(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c0px;
        double g_4 = c0px * c00x + b00;
        double g_5 = b00 * c00x + b10 * c0px + c00x * g_4;
        double g_6 = c0px * c0px + b01;
        double g_7 = b00 * c0px + b01 * c00x + c0px * g_4;
        double g_8 = 2 * b00 * g_4 + b10 * g_6 + c00x * g_7;
        double g_9 = 1;
        double g_10 = c00y;
        double g_11 = c00y * c00y + b10;
        double g_12 = c0py;
        double g_13 = c0py * c00y + b00;
        double g_14 = b00 * c00y + b10 * c0py + c00y * g_13;
        double g_15 = c0py * c0py + b01;
        double g_16 = b00 * c0py + b01 * c00y + c0py * g_13;
        double g_17 = 2 * b00 * g_13 + b10 * g_15 + c00y * g_16;
        double g_18 = weight0 * fac;
        double g_19 = c00z * g_18;
        double g_20 = b10 * g_18 + c00z * g_19;
        double g_21 = c0pz * g_18;
        double g_22 = b00 * g_18 + c0pz * g_19;
        double g_23 = b00 * g_19 + b10 * g_21 + c00z * g_22;
        double g_24 = b01 * g_18 + c0pz * g_21;
        double g_25 = b00 * g_21 + b01 * g_19 + c0pz * g_22;
        double g_26 = 2 * b00 * g_22 + b10 * g_24 + c00z * g_25;
        gout0 += g_8 * g_9 * g_18;
        gout1 += g_7 * g_10 * g_18;
        gout2 += g_7 * g_9 * g_19;
        gout3 += g_6 * g_11 * g_18;
        gout4 += g_6 * g_10 * g_19;
        gout5 += g_6 * g_9 * g_20;
        gout6 += g_5 * g_12 * g_18;
        gout7 += g_4 * g_13 * g_18;
        gout8 += g_4 * g_12 * g_19;
        gout9 += g_3 * g_14 * g_18;
        gout10 += g_3 * g_13 * g_19;
        gout11 += g_3 * g_12 * g_20;
        gout12 += g_5 * g_9 * g_21;
        gout13 += g_4 * g_10 * g_21;
        gout14 += g_4 * g_9 * g_22;
        gout15 += g_3 * g_11 * g_21;
        gout16 += g_3 * g_10 * g_22;
        gout17 += g_3 * g_9 * g_23;
        gout18 += g_2 * g_15 * g_18;
        gout19 += g_1 * g_16 * g_18;
        gout20 += g_1 * g_15 * g_19;
        gout21 += g_0 * g_17 * g_18;
        gout22 += g_0 * g_16 * g_19;
        gout23 += g_0 * g_15 * g_20;
        gout24 += g_2 * g_12 * g_21;
        gout25 += g_1 * g_13 * g_21;
        gout26 += g_1 * g_12 * g_22;
        gout27 += g_0 * g_14 * g_21;
        gout28 += g_0 * g_13 * g_22;
        gout29 += g_0 * g_12 * g_23;
        gout30 += g_2 * g_9 * g_24;
        gout31 += g_1 * g_10 * g_24;
        gout32 += g_1 * g_9 * g_25;
        gout33 += g_0 * g_11 * g_24;
        gout34 += g_0 * g_10 * g_25;
        gout35 += g_0 * g_9 * g_26;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 1 * kstride, gout6);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout7);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout8);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout9);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout10);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 2 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout14);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout15);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout16);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout17);
    atomicAdd(peri + 3 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout20);
    atomicAdd(peri + 3 * istride + 3 * kstride, gout21);
    atomicAdd(peri + 4 * istride + 3 * kstride, gout22);
    atomicAdd(peri + 5 * istride + 3 * kstride, gout23);
    atomicAdd(peri + 4 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout26);
    atomicAdd(peri + 3 * istride + 4 * kstride, gout27);
    atomicAdd(peri + 4 * istride + 4 * kstride, gout28);
    atomicAdd(peri + 5 * istride + 4 * kstride, gout29);
    atomicAdd(peri + 5 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout32);
    atomicAdd(peri + 3 * istride + 5 * kstride, gout33);
    atomicAdd(peri + 4 * istride + 5 * kstride, gout34);
    atomicAdd(peri + 5 * istride + 5 * kstride, gout35);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel2021(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c0px;
        double g_4 = c0px * c00x + b00;
        double g_5 = b00 * c00x + b10 * c0px + c00x * g_4;
        double g_6 = c0px * c0px + b01;
        double g_7 = b00 * c0px + b01 * c00x + c0px * g_4;
        double g_8 = 2 * b00 * g_4 + b10 * g_6 + c00x * g_7;
        double g_9 = c0px + xkxl;
        double g_10 = c00x * (c0px + xkxl) + b00;
        double g_11 = b00 * c00x + b10 * c0px + c00x * g_4 + xkxl * g_2;
        double g_12 = c0px * (c0px + xkxl) + b01;
        double g_13 = b00 * c0px + b01 * c00x + c0px * g_4 + xkxl * g_4;
        double g_14 = 2 * b00 * g_4 + b10 * g_6 + c00x * g_7 + xkxl * g_5;
        double g_15 = c0px * (2 * b01 + g_6) + xkxl * g_6;
        double g_16 = 2 * b01 * g_4 + b00 * g_6 + c0px * g_7 + xkxl * g_7;
        double g_17 = xkxl * g_8 +
                      c00x * (c0px * g_7 + 2 * b01 * g_4 + b00 * g_6) +
                      b10 * (c0px * g_6 + 2 * b01 * c0px) + 3 * b00 * g_7;
        double g_18 = 1;
        double g_19 = c00y;
        double g_20 = c00y * c00y + b10;
        double g_21 = c0py;
        double g_22 = c0py * c00y + b00;
        double g_23 = b00 * c00y + b10 * c0py + c00y * g_22;
        double g_24 = c0py * c0py + b01;
        double g_25 = b00 * c0py + b01 * c00y + c0py * g_22;
        double g_26 = 2 * b00 * g_22 + b10 * g_24 + c00y * g_25;
        double g_27 = c0py + ykyl;
        double g_28 = c00y * (c0py + ykyl) + b00;
        double g_29 = b00 * c00y + b10 * c0py + c00y * g_22 + ykyl * g_20;
        double g_30 = c0py * (c0py + ykyl) + b01;
        double g_31 = b00 * c0py + b01 * c00y + c0py * g_22 + ykyl * g_22;
        double g_32 = 2 * b00 * g_22 + b10 * g_24 + c00y * g_25 + ykyl * g_23;
        double g_33 = c0py * (2 * b01 + g_24) + ykyl * g_24;
        double g_34 = 2 * b01 * g_22 + b00 * g_24 + c0py * g_25 + ykyl * g_25;
        double g_35 = ykyl * g_26 +
                      c00y * (c0py * g_25 + 2 * b01 * g_22 + b00 * g_24) +
                      b10 * (c0py * g_24 + 2 * b01 * c0py) + 3 * b00 * g_25;
        double g_36 = weight0 * fac;
        double g_37 = c00z * g_36;
        double g_38 = b10 * g_36 + c00z * g_37;
        double g_39 = c0pz * g_36;
        double g_40 = b00 * g_36 + c0pz * g_37;
        double g_41 = b00 * g_37 + b10 * g_39 + c00z * g_40;
        double g_42 = b01 * g_36 + c0pz * g_39;
        double g_43 = b00 * g_39 + b01 * g_37 + c0pz * g_40;
        double g_44 = 2 * b00 * g_40 + b10 * g_42 + c00z * g_43;
        double g_45 = g_36 * (c0pz + zkzl);
        double g_46 = b00 * g_36 + c0pz * g_37 + zkzl * g_37;
        double g_47 = b00 * g_37 + b10 * g_39 + c00z * g_40 + zkzl * g_38;
        double g_48 = b01 * g_36 + c0pz * g_39 + zkzl * g_39;
        double g_49 = b00 * g_39 + b01 * g_37 + c0pz * g_40 + zkzl * g_40;
        double g_50 = 2 * b00 * g_40 + b10 * g_42 + c00z * g_43 + zkzl * g_41;
        double g_51 = 2 * b01 * g_39 + c0pz * g_42 + zkzl * g_42;
        double g_52 = 2 * b01 * g_40 + b00 * g_42 + c0pz * g_43 + zkzl * g_43;
        double g_53 = zkzl * g_44 +
                      c00z * (c0pz * g_43 + 2 * b01 * g_40 + b00 * g_42) +
                      b10 * (c0pz * g_42 + 2 * b01 * g_39) + 3 * b00 * g_43;
        gout0 += g_17 * g_18 * g_36;
        gout1 += g_16 * g_19 * g_36;
        gout2 += g_16 * g_18 * g_37;
        gout3 += g_15 * g_20 * g_36;
        gout4 += g_15 * g_19 * g_37;
        gout5 += g_15 * g_18 * g_38;
        gout6 += g_14 * g_21 * g_36;
        gout7 += g_13 * g_22 * g_36;
        gout8 += g_13 * g_21 * g_37;
        gout9 += g_12 * g_23 * g_36;
        gout10 += g_12 * g_22 * g_37;
        gout11 += g_12 * g_21 * g_38;
        gout12 += g_14 * g_18 * g_39;
        gout13 += g_13 * g_19 * g_39;
        gout14 += g_13 * g_18 * g_40;
        gout15 += g_12 * g_20 * g_39;
        gout16 += g_12 * g_19 * g_40;
        gout17 += g_12 * g_18 * g_41;
        gout18 += g_11 * g_24 * g_36;
        gout19 += g_10 * g_25 * g_36;
        gout20 += g_10 * g_24 * g_37;
        gout21 += g_9 * g_26 * g_36;
        gout22 += g_9 * g_25 * g_37;
        gout23 += g_9 * g_24 * g_38;
        gout24 += g_11 * g_21 * g_39;
        gout25 += g_10 * g_22 * g_39;
        gout26 += g_10 * g_21 * g_40;
        gout27 += g_9 * g_23 * g_39;
        gout28 += g_9 * g_22 * g_40;
        gout29 += g_9 * g_21 * g_41;
        gout30 += g_11 * g_18 * g_42;
        gout31 += g_10 * g_19 * g_42;
        gout32 += g_10 * g_18 * g_43;
        gout33 += g_9 * g_20 * g_42;
        gout34 += g_9 * g_19 * g_43;
        gout35 += g_9 * g_18 * g_44;
        gout36 += g_8 * g_27 * g_36;
        gout37 += g_7 * g_28 * g_36;
        gout38 += g_7 * g_27 * g_37;
        gout39 += g_6 * g_29 * g_36;
        gout40 += g_6 * g_28 * g_37;
        gout41 += g_6 * g_27 * g_38;
        gout42 += g_5 * g_30 * g_36;
        gout43 += g_4 * g_31 * g_36;
        gout44 += g_4 * g_30 * g_37;
        gout45 += g_3 * g_32 * g_36;
        gout46 += g_3 * g_31 * g_37;
        gout47 += g_3 * g_30 * g_38;
        gout48 += g_5 * g_27 * g_39;
        gout49 += g_4 * g_28 * g_39;
        gout50 += g_4 * g_27 * g_40;
        gout51 += g_3 * g_29 * g_39;
        gout52 += g_3 * g_28 * g_40;
        gout53 += g_3 * g_27 * g_41;
        gout54 += g_2 * g_33 * g_36;
        gout55 += g_1 * g_34 * g_36;
        gout56 += g_1 * g_33 * g_37;
        gout57 += g_0 * g_35 * g_36;
        gout58 += g_0 * g_34 * g_37;
        gout59 += g_0 * g_33 * g_38;
        gout60 += g_2 * g_30 * g_39;
        gout61 += g_1 * g_31 * g_39;
        gout62 += g_1 * g_30 * g_40;
        gout63 += g_0 * g_32 * g_39;
        gout64 += g_0 * g_31 * g_40;
        gout65 += g_0 * g_30 * g_41;
        gout66 += g_2 * g_27 * g_42;
        gout67 += g_1 * g_28 * g_42;
        gout68 += g_1 * g_27 * g_43;
        gout69 += g_0 * g_29 * g_42;
        gout70 += g_0 * g_28 * g_43;
        gout71 += g_0 * g_27 * g_44;
        gout72 += g_8 * g_18 * g_45;
        gout73 += g_7 * g_19 * g_45;
        gout74 += g_7 * g_18 * g_46;
        gout75 += g_6 * g_20 * g_45;
        gout76 += g_6 * g_19 * g_46;
        gout77 += g_6 * g_18 * g_47;
        gout78 += g_5 * g_21 * g_45;
        gout79 += g_4 * g_22 * g_45;
        gout80 += g_4 * g_21 * g_46;
        gout81 += g_3 * g_23 * g_45;
        gout82 += g_3 * g_22 * g_46;
        gout83 += g_3 * g_21 * g_47;
        gout84 += g_5 * g_18 * g_48;
        gout85 += g_4 * g_19 * g_48;
        gout86 += g_4 * g_18 * g_49;
        gout87 += g_3 * g_20 * g_48;
        gout88 += g_3 * g_19 * g_49;
        gout89 += g_3 * g_18 * g_50;
        gout90 += g_2 * g_24 * g_45;
        gout91 += g_1 * g_25 * g_45;
        gout92 += g_1 * g_24 * g_46;
        gout93 += g_0 * g_26 * g_45;
        gout94 += g_0 * g_25 * g_46;
        gout95 += g_0 * g_24 * g_47;
        gout96 += g_2 * g_21 * g_48;
        gout97 += g_1 * g_22 * g_48;
        gout98 += g_1 * g_21 * g_49;
        gout99 += g_0 * g_23 * g_48;
        gout100 += g_0 * g_22 * g_49;
        gout101 += g_0 * g_21 * g_50;
        gout102 += g_2 * g_18 * g_51;
        gout103 += g_1 * g_19 * g_51;
        gout104 += g_1 * g_18 * g_52;
        gout105 += g_0 * g_20 * g_51;
        gout106 += g_0 * g_19 * g_52;
        gout107 += g_0 * g_18 * g_53;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        gout81 = reduce(gout81);
        gout82 = reduce(gout82);
        gout83 = reduce(gout83);
        gout84 = reduce(gout84);
        gout85 = reduce(gout85);
        gout86 = reduce(gout86);
        gout87 = reduce(gout87);
        gout88 = reduce(gout88);
        gout89 = reduce(gout89);
        gout90 = reduce(gout90);
        gout91 = reduce(gout91);
        gout92 = reduce(gout92);
        gout93 = reduce(gout93);
        gout94 = reduce(gout94);
        gout95 = reduce(gout95);
        gout96 = reduce(gout96);
        gout97 = reduce(gout97);
        gout98 = reduce(gout98);
        gout99 = reduce(gout99);
        gout100 = reduce(gout100);
        gout101 = reduce(gout101);
        gout102 = reduce(gout102);
        gout103 = reduce(gout103);
        gout104 = reduce(gout104);
        gout105 = reduce(gout105);
        gout106 = reduce(gout106);
        gout107 = reduce(gout107);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 1 * kstride, gout6);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout7);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout8);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout9);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout10);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 2 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout14);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout15);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout16);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout17);
    atomicAdd(peri + 3 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout20);
    atomicAdd(peri + 3 * istride + 3 * kstride, gout21);
    atomicAdd(peri + 4 * istride + 3 * kstride, gout22);
    atomicAdd(peri + 5 * istride + 3 * kstride, gout23);
    atomicAdd(peri + 4 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout26);
    atomicAdd(peri + 3 * istride + 4 * kstride, gout27);
    atomicAdd(peri + 4 * istride + 4 * kstride, gout28);
    atomicAdd(peri + 5 * istride + 4 * kstride, gout29);
    atomicAdd(peri + 5 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout32);
    atomicAdd(peri + 3 * istride + 5 * kstride, gout33);
    atomicAdd(peri + 4 * istride + 5 * kstride, gout34);
    atomicAdd(peri + 5 * istride + 5 * kstride, gout35);
    atomicAdd(peri + 1 * lstride, gout36);
    atomicAdd(peri + 1 * istride + 1 * lstride, gout37);
    atomicAdd(peri + 2 * istride + 1 * lstride, gout38);
    atomicAdd(peri + 3 * istride + 1 * lstride, gout39);
    atomicAdd(peri + 4 * istride + 1 * lstride, gout40);
    atomicAdd(peri + 5 * istride + 1 * lstride, gout41);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout42);
    atomicAdd(peri + 1 * istride + 1 * kstride + 1 * lstride, gout43);
    atomicAdd(peri + 2 * istride + 1 * kstride + 1 * lstride, gout44);
    atomicAdd(peri + 3 * istride + 1 * kstride + 1 * lstride, gout45);
    atomicAdd(peri + 4 * istride + 1 * kstride + 1 * lstride, gout46);
    atomicAdd(peri + 5 * istride + 1 * kstride + 1 * lstride, gout47);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout48);
    atomicAdd(peri + 1 * istride + 2 * kstride + 1 * lstride, gout49);
    atomicAdd(peri + 2 * istride + 2 * kstride + 1 * lstride, gout50);
    atomicAdd(peri + 3 * istride + 2 * kstride + 1 * lstride, gout51);
    atomicAdd(peri + 4 * istride + 2 * kstride + 1 * lstride, gout52);
    atomicAdd(peri + 5 * istride + 2 * kstride + 1 * lstride, gout53);
    atomicAdd(peri + 3 * kstride + 1 * lstride, gout54);
    atomicAdd(peri + 1 * istride + 3 * kstride + 1 * lstride, gout55);
    atomicAdd(peri + 2 * istride + 3 * kstride + 1 * lstride, gout56);
    atomicAdd(peri + 3 * istride + 3 * kstride + 1 * lstride, gout57);
    atomicAdd(peri + 4 * istride + 3 * kstride + 1 * lstride, gout58);
    atomicAdd(peri + 5 * istride + 3 * kstride + 1 * lstride, gout59);
    atomicAdd(peri + 4 * kstride + 1 * lstride, gout60);
    atomicAdd(peri + 1 * istride + 4 * kstride + 1 * lstride, gout61);
    atomicAdd(peri + 2 * istride + 4 * kstride + 1 * lstride, gout62);
    atomicAdd(peri + 3 * istride + 4 * kstride + 1 * lstride, gout63);
    atomicAdd(peri + 4 * istride + 4 * kstride + 1 * lstride, gout64);
    atomicAdd(peri + 5 * istride + 4 * kstride + 1 * lstride, gout65);
    atomicAdd(peri + 5 * kstride + 1 * lstride, gout66);
    atomicAdd(peri + 1 * istride + 5 * kstride + 1 * lstride, gout67);
    atomicAdd(peri + 2 * istride + 5 * kstride + 1 * lstride, gout68);
    atomicAdd(peri + 3 * istride + 5 * kstride + 1 * lstride, gout69);
    atomicAdd(peri + 4 * istride + 5 * kstride + 1 * lstride, gout70);
    atomicAdd(peri + 5 * istride + 5 * kstride + 1 * lstride, gout71);
    atomicAdd(peri + 2 * lstride, gout72);
    atomicAdd(peri + 1 * istride + 2 * lstride, gout73);
    atomicAdd(peri + 2 * istride + 2 * lstride, gout74);
    atomicAdd(peri + 3 * istride + 2 * lstride, gout75);
    atomicAdd(peri + 4 * istride + 2 * lstride, gout76);
    atomicAdd(peri + 5 * istride + 2 * lstride, gout77);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout78);
    atomicAdd(peri + 1 * istride + 1 * kstride + 2 * lstride, gout79);
    atomicAdd(peri + 2 * istride + 1 * kstride + 2 * lstride, gout80);
    atomicAdd(peri + 3 * istride + 1 * kstride + 2 * lstride, gout81);
    atomicAdd(peri + 4 * istride + 1 * kstride + 2 * lstride, gout82);
    atomicAdd(peri + 5 * istride + 1 * kstride + 2 * lstride, gout83);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout84);
    atomicAdd(peri + 1 * istride + 2 * kstride + 2 * lstride, gout85);
    atomicAdd(peri + 2 * istride + 2 * kstride + 2 * lstride, gout86);
    atomicAdd(peri + 3 * istride + 2 * kstride + 2 * lstride, gout87);
    atomicAdd(peri + 4 * istride + 2 * kstride + 2 * lstride, gout88);
    atomicAdd(peri + 5 * istride + 2 * kstride + 2 * lstride, gout89);
    atomicAdd(peri + 3 * kstride + 2 * lstride, gout90);
    atomicAdd(peri + 1 * istride + 3 * kstride + 2 * lstride, gout91);
    atomicAdd(peri + 2 * istride + 3 * kstride + 2 * lstride, gout92);
    atomicAdd(peri + 3 * istride + 3 * kstride + 2 * lstride, gout93);
    atomicAdd(peri + 4 * istride + 3 * kstride + 2 * lstride, gout94);
    atomicAdd(peri + 5 * istride + 3 * kstride + 2 * lstride, gout95);
    atomicAdd(peri + 4 * kstride + 2 * lstride, gout96);
    atomicAdd(peri + 1 * istride + 4 * kstride + 2 * lstride, gout97);
    atomicAdd(peri + 2 * istride + 4 * kstride + 2 * lstride, gout98);
    atomicAdd(peri + 3 * istride + 4 * kstride + 2 * lstride, gout99);
    atomicAdd(peri + 4 * istride + 4 * kstride + 2 * lstride, gout100);
    atomicAdd(peri + 5 * istride + 4 * kstride + 2 * lstride, gout101);
    atomicAdd(peri + 5 * kstride + 2 * lstride, gout102);
    atomicAdd(peri + 1 * istride + 5 * kstride + 2 * lstride, gout103);
    atomicAdd(peri + 2 * istride + 5 * kstride + 2 * lstride, gout104);
    atomicAdd(peri + 3 * istride + 5 * kstride + 2 * lstride, gout105);
    atomicAdd(peri + 4 * istride + 5 * kstride + 2 * lstride, gout106);
    atomicAdd(peri + 5 * istride + 5 * kstride + 2 * lstride, gout107);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel2030(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c0px;
        double g_4 = c0px * c00x + b00;
        double g_5 = b00 * c00x + b10 * c0px + c00x * g_4;
        double g_6 = c0px * c0px + b01;
        double g_7 = b00 * c0px + b01 * c00x + c0px * g_4;
        double g_8 = 2 * b00 * g_4 + b10 * g_6 + c00x * g_7;
        double g_9 = c0px * (2 * b01 + g_6);
        double g_10 = 2 * b01 * g_4 + b00 * g_6 + c0px * g_7;
        double g_11 = 3 * b00 * g_7 + b10 * g_9 + c00x * g_10;
        double g_12 = 1;
        double g_13 = c00y;
        double g_14 = c00y * c00y + b10;
        double g_15 = c0py;
        double g_16 = c0py * c00y + b00;
        double g_17 = b00 * c00y + b10 * c0py + c00y * g_16;
        double g_18 = c0py * c0py + b01;
        double g_19 = b00 * c0py + b01 * c00y + c0py * g_16;
        double g_20 = 2 * b00 * g_16 + b10 * g_18 + c00y * g_19;
        double g_21 = c0py * (2 * b01 + g_18);
        double g_22 = 2 * b01 * g_16 + b00 * g_18 + c0py * g_19;
        double g_23 = 3 * b00 * g_19 + b10 * g_21 + c00y * g_22;
        double g_24 = weight0 * fac;
        double g_25 = c00z * g_24;
        double g_26 = b10 * g_24 + c00z * g_25;
        double g_27 = c0pz * g_24;
        double g_28 = b00 * g_24 + c0pz * g_25;
        double g_29 = b00 * g_25 + b10 * g_27 + c00z * g_28;
        double g_30 = b01 * g_24 + c0pz * g_27;
        double g_31 = b00 * g_27 + b01 * g_25 + c0pz * g_28;
        double g_32 = 2 * b00 * g_28 + b10 * g_30 + c00z * g_31;
        double g_33 = 2 * b01 * g_27 + c0pz * g_30;
        double g_34 = 2 * b01 * g_28 + b00 * g_30 + c0pz * g_31;
        double g_35 = 3 * b00 * g_31 + b10 * g_33 + c00z * g_34;
        gout0 += g_11 * g_12 * g_24;
        gout1 += g_10 * g_13 * g_24;
        gout2 += g_10 * g_12 * g_25;
        gout3 += g_9 * g_14 * g_24;
        gout4 += g_9 * g_13 * g_25;
        gout5 += g_9 * g_12 * g_26;
        gout6 += g_8 * g_15 * g_24;
        gout7 += g_7 * g_16 * g_24;
        gout8 += g_7 * g_15 * g_25;
        gout9 += g_6 * g_17 * g_24;
        gout10 += g_6 * g_16 * g_25;
        gout11 += g_6 * g_15 * g_26;
        gout12 += g_8 * g_12 * g_27;
        gout13 += g_7 * g_13 * g_27;
        gout14 += g_7 * g_12 * g_28;
        gout15 += g_6 * g_14 * g_27;
        gout16 += g_6 * g_13 * g_28;
        gout17 += g_6 * g_12 * g_29;
        gout18 += g_5 * g_18 * g_24;
        gout19 += g_4 * g_19 * g_24;
        gout20 += g_4 * g_18 * g_25;
        gout21 += g_3 * g_20 * g_24;
        gout22 += g_3 * g_19 * g_25;
        gout23 += g_3 * g_18 * g_26;
        gout24 += g_5 * g_15 * g_27;
        gout25 += g_4 * g_16 * g_27;
        gout26 += g_4 * g_15 * g_28;
        gout27 += g_3 * g_17 * g_27;
        gout28 += g_3 * g_16 * g_28;
        gout29 += g_3 * g_15 * g_29;
        gout30 += g_5 * g_12 * g_30;
        gout31 += g_4 * g_13 * g_30;
        gout32 += g_4 * g_12 * g_31;
        gout33 += g_3 * g_14 * g_30;
        gout34 += g_3 * g_13 * g_31;
        gout35 += g_3 * g_12 * g_32;
        gout36 += g_2 * g_21 * g_24;
        gout37 += g_1 * g_22 * g_24;
        gout38 += g_1 * g_21 * g_25;
        gout39 += g_0 * g_23 * g_24;
        gout40 += g_0 * g_22 * g_25;
        gout41 += g_0 * g_21 * g_26;
        gout42 += g_2 * g_18 * g_27;
        gout43 += g_1 * g_19 * g_27;
        gout44 += g_1 * g_18 * g_28;
        gout45 += g_0 * g_20 * g_27;
        gout46 += g_0 * g_19 * g_28;
        gout47 += g_0 * g_18 * g_29;
        gout48 += g_2 * g_15 * g_30;
        gout49 += g_1 * g_16 * g_30;
        gout50 += g_1 * g_15 * g_31;
        gout51 += g_0 * g_17 * g_30;
        gout52 += g_0 * g_16 * g_31;
        gout53 += g_0 * g_15 * g_32;
        gout54 += g_2 * g_12 * g_33;
        gout55 += g_1 * g_13 * g_33;
        gout56 += g_1 * g_12 * g_34;
        gout57 += g_0 * g_14 * g_33;
        gout58 += g_0 * g_13 * g_34;
        gout59 += g_0 * g_12 * g_35;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 1 * kstride, gout6);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout7);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout8);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout9);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout10);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 2 * kstride, gout12);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout13);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout14);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout15);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout16);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout17);
    atomicAdd(peri + 3 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout20);
    atomicAdd(peri + 3 * istride + 3 * kstride, gout21);
    atomicAdd(peri + 4 * istride + 3 * kstride, gout22);
    atomicAdd(peri + 5 * istride + 3 * kstride, gout23);
    atomicAdd(peri + 4 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout26);
    atomicAdd(peri + 3 * istride + 4 * kstride, gout27);
    atomicAdd(peri + 4 * istride + 4 * kstride, gout28);
    atomicAdd(peri + 5 * istride + 4 * kstride, gout29);
    atomicAdd(peri + 5 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout32);
    atomicAdd(peri + 3 * istride + 5 * kstride, gout33);
    atomicAdd(peri + 4 * istride + 5 * kstride, gout34);
    atomicAdd(peri + 5 * istride + 5 * kstride, gout35);
    atomicAdd(peri + 6 * kstride, gout36);
    atomicAdd(peri + 1 * istride + 6 * kstride, gout37);
    atomicAdd(peri + 2 * istride + 6 * kstride, gout38);
    atomicAdd(peri + 3 * istride + 6 * kstride, gout39);
    atomicAdd(peri + 4 * istride + 6 * kstride, gout40);
    atomicAdd(peri + 5 * istride + 6 * kstride, gout41);
    atomicAdd(peri + 7 * kstride, gout42);
    atomicAdd(peri + 1 * istride + 7 * kstride, gout43);
    atomicAdd(peri + 2 * istride + 7 * kstride, gout44);
    atomicAdd(peri + 3 * istride + 7 * kstride, gout45);
    atomicAdd(peri + 4 * istride + 7 * kstride, gout46);
    atomicAdd(peri + 5 * istride + 7 * kstride, gout47);
    atomicAdd(peri + 8 * kstride, gout48);
    atomicAdd(peri + 1 * istride + 8 * kstride, gout49);
    atomicAdd(peri + 2 * istride + 8 * kstride, gout50);
    atomicAdd(peri + 3 * istride + 8 * kstride, gout51);
    atomicAdd(peri + 4 * istride + 8 * kstride, gout52);
    atomicAdd(peri + 5 * istride + 8 * kstride, gout53);
    atomicAdd(peri + 9 * kstride, gout54);
    atomicAdd(peri + 1 * istride + 9 * kstride, gout55);
    atomicAdd(peri + 2 * istride + 9 * kstride, gout56);
    atomicAdd(peri + 3 * istride + 9 * kstride, gout57);
    atomicAdd(peri + 4 * istride + 9 * kstride, gout58);
    atomicAdd(peri + 5 * istride + 9 * kstride, gout59);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel2110(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x + xixj;
        double g_4 = c00x * (c00x + xixj) + b10;
        double g_5 = c00x * (2 * b10 + g_2) + xixj * g_2;
        double g_6 = c0px;
        double g_7 = c0px * c00x + b00;
        double g_8 = b00 * c00x + b10 * c0px + c00x * g_7;
        double g_9 = c0px * (c00x + xixj) + b00;
        double g_10 = b00 * c00x + b10 * c0px + c00x * g_7 + xixj * g_7;
        double g_11 = 2 * b10 * g_7 + b00 * g_2 + c00x * g_8 + xixj * g_8;
        double g_12 = 1;
        double g_13 = c00y;
        double g_14 = c00y * c00y + b10;
        double g_15 = c00y + yiyj;
        double g_16 = c00y * (c00y + yiyj) + b10;
        double g_17 = c00y * (2 * b10 + g_14) + yiyj * g_14;
        double g_18 = c0py;
        double g_19 = c0py * c00y + b00;
        double g_20 = b00 * c00y + b10 * c0py + c00y * g_19;
        double g_21 = c0py * (c00y + yiyj) + b00;
        double g_22 = b00 * c00y + b10 * c0py + c00y * g_19 + yiyj * g_19;
        double g_23 = 2 * b10 * g_19 + b00 * g_14 + c00y * g_20 + yiyj * g_20;
        double g_24 = weight0 * fac;
        double g_25 = c00z * g_24;
        double g_26 = b10 * g_24 + c00z * g_25;
        double g_27 = g_24 * (c00z + zizj);
        double g_28 = b10 * g_24 + c00z * g_25 + zizj * g_25;
        double g_29 = 2 * b10 * g_25 + c00z * g_26 + zizj * g_26;
        double g_30 = c0pz * g_24;
        double g_31 = b00 * g_24 + c0pz * g_25;
        double g_32 = b00 * g_25 + b10 * g_30 + c00z * g_31;
        double g_33 = b00 * g_24 + c0pz * g_25 + zizj * g_30;
        double g_34 = b00 * g_25 + b10 * g_30 + c00z * g_31 + zizj * g_31;
        double g_35 = 2 * b10 * g_31 + b00 * g_26 + c00z * g_32 + zizj * g_32;
        gout0 += g_11 * g_12 * g_24;
        gout1 += g_10 * g_13 * g_24;
        gout2 += g_10 * g_12 * g_25;
        gout3 += g_9 * g_14 * g_24;
        gout4 += g_9 * g_13 * g_25;
        gout5 += g_9 * g_12 * g_26;
        gout6 += g_8 * g_15 * g_24;
        gout7 += g_7 * g_16 * g_24;
        gout8 += g_7 * g_15 * g_25;
        gout9 += g_6 * g_17 * g_24;
        gout10 += g_6 * g_16 * g_25;
        gout11 += g_6 * g_15 * g_26;
        gout12 += g_8 * g_12 * g_27;
        gout13 += g_7 * g_13 * g_27;
        gout14 += g_7 * g_12 * g_28;
        gout15 += g_6 * g_14 * g_27;
        gout16 += g_6 * g_13 * g_28;
        gout17 += g_6 * g_12 * g_29;
        gout18 += g_5 * g_18 * g_24;
        gout19 += g_4 * g_19 * g_24;
        gout20 += g_4 * g_18 * g_25;
        gout21 += g_3 * g_20 * g_24;
        gout22 += g_3 * g_19 * g_25;
        gout23 += g_3 * g_18 * g_26;
        gout24 += g_2 * g_21 * g_24;
        gout25 += g_1 * g_22 * g_24;
        gout26 += g_1 * g_21 * g_25;
        gout27 += g_0 * g_23 * g_24;
        gout28 += g_0 * g_22 * g_25;
        gout29 += g_0 * g_21 * g_26;
        gout30 += g_2 * g_18 * g_27;
        gout31 += g_1 * g_19 * g_27;
        gout32 += g_1 * g_18 * g_28;
        gout33 += g_0 * g_20 * g_27;
        gout34 += g_0 * g_19 * g_28;
        gout35 += g_0 * g_18 * g_29;
        gout36 += g_5 * g_12 * g_30;
        gout37 += g_4 * g_13 * g_30;
        gout38 += g_4 * g_12 * g_31;
        gout39 += g_3 * g_14 * g_30;
        gout40 += g_3 * g_13 * g_31;
        gout41 += g_3 * g_12 * g_32;
        gout42 += g_2 * g_15 * g_30;
        gout43 += g_1 * g_16 * g_30;
        gout44 += g_1 * g_15 * g_31;
        gout45 += g_0 * g_17 * g_30;
        gout46 += g_0 * g_16 * g_31;
        gout47 += g_0 * g_15 * g_32;
        gout48 += g_2 * g_12 * g_33;
        gout49 += g_1 * g_13 * g_33;
        gout50 += g_1 * g_12 * g_34;
        gout51 += g_0 * g_14 * g_33;
        gout52 += g_0 * g_13 * g_34;
        gout53 += g_0 * g_12 * g_35;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 1 * jstride, gout6);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout7);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout8);
    atomicAdd(peri + 3 * istride + 1 * jstride, gout9);
    atomicAdd(peri + 4 * istride + 1 * jstride, gout10);
    atomicAdd(peri + 5 * istride + 1 * jstride, gout11);
    atomicAdd(peri + 2 * jstride, gout12);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout13);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout14);
    atomicAdd(peri + 3 * istride + 2 * jstride, gout15);
    atomicAdd(peri + 4 * istride + 2 * jstride, gout16);
    atomicAdd(peri + 5 * istride + 2 * jstride, gout17);
    atomicAdd(peri + 1 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout20);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout21);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout22);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout23);
    atomicAdd(peri + 1 * jstride + 1 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * kstride, gout26);
    atomicAdd(peri + 3 * istride + 1 * jstride + 1 * kstride, gout27);
    atomicAdd(peri + 4 * istride + 1 * jstride + 1 * kstride, gout28);
    atomicAdd(peri + 5 * istride + 1 * jstride + 1 * kstride, gout29);
    atomicAdd(peri + 2 * jstride + 1 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * kstride, gout32);
    atomicAdd(peri + 3 * istride + 2 * jstride + 1 * kstride, gout33);
    atomicAdd(peri + 4 * istride + 2 * jstride + 1 * kstride, gout34);
    atomicAdd(peri + 5 * istride + 2 * jstride + 1 * kstride, gout35);
    atomicAdd(peri + 2 * kstride, gout36);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout37);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout38);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout39);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout40);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout41);
    atomicAdd(peri + 1 * jstride + 2 * kstride, gout42);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * kstride, gout43);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * kstride, gout44);
    atomicAdd(peri + 3 * istride + 1 * jstride + 2 * kstride, gout45);
    atomicAdd(peri + 4 * istride + 1 * jstride + 2 * kstride, gout46);
    atomicAdd(peri + 5 * istride + 1 * jstride + 2 * kstride, gout47);
    atomicAdd(peri + 2 * jstride + 2 * kstride, gout48);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * kstride, gout49);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * kstride, gout50);
    atomicAdd(peri + 3 * istride + 2 * jstride + 2 * kstride, gout51);
    atomicAdd(peri + 4 * istride + 2 * jstride + 2 * kstride, gout52);
    atomicAdd(peri + 5 * istride + 2 * jstride + 2 * kstride, gout53);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel2111(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x + xixj;
        double g_4 = c00x * (c00x + xixj) + b10;
        double g_5 = c00x * (2 * b10 + g_2) + xixj * g_2;
        double g_6 = c0px;
        double g_7 = c0px * c00x + b00;
        double g_8 = b00 * c00x + b10 * c0px + c00x * g_7;
        double g_9 = c0px * (c00x + xixj) + b00;
        double g_10 = b00 * c00x + b10 * c0px + c00x * g_7 + xixj * g_7;
        double g_11 = 2 * b10 * g_7 + b00 * g_2 + c00x * g_8 + xixj * g_8;
        double g_12 = c0px + xkxl;
        double g_13 = c00x * (c0px + xkxl) + b00;
        double g_14 = b00 * c00x + b10 * c0px + c00x * g_7 + xkxl * g_2;
        double g_15 = xkxl * (xixj + c00x) + xixj * c0px + c0px * c00x + b00;
        double g_16 = xkxl * (xixj * c00x + c00x * c00x + b10) + xixj * g_7 +
                      c00x * g_7 + b10 * c0px + b00 * c00x;
        double g_17 = xkxl * (xixj * g_2 + c00x * g_2 + 2 * b10 * c00x) +
                      xixj * g_8 + c00x * g_8 + 2 * b10 * g_7 + b00 * g_2;
        double g_18 = c0px * (c0px + xkxl) + b01;
        double g_19 = b00 * c0px + b01 * c00x + c0px * g_7 + xkxl * g_7;
        double g_20 = xkxl * g_8 +
                      c00x * (c0px * g_7 + b01 * c00x + b00 * c0px) +
                      b10 * (c0px * c0px + b01) + 2 * b00 * g_7;
        double g_21 = xkxl * (xixj * c0px + c0px * c00x + b00) +
                      xixj * (c0px * c0px + b01) + c0px * g_7 + b01 * c00x +
                      b00 * c0px;
        double g_22 =
            xkxl * (xixj * g_7 + c00x * g_7 + b10 * c0px + b00 * c00x) +
            xixj * (c0px * g_7 + b01 * c00x + b00 * c0px) +
            c00x * (c0px * g_7 + b01 * c00x + b00 * c0px) +
            b10 * (c0px * c0px + b01) + 2 * b00 * g_7;
        double g_23 =
            xkxl * (xixj * g_8 + c00x * g_8 + 2 * b10 * g_7 + b00 * g_2) +
            xixj * (c00x * (c0px * g_7 + b01 * c00x + b00 * c0px) +
                       b10 * (c0px * c0px + b01) + 2 * b00 * g_7) +
            c00x * (c00x * (c0px * g_7 + b01 * c00x + b00 * c0px) +
                       b10 * (c0px * c0px + b01) + 2 * b00 * g_7) +
            2 * b10 * (c0px * g_7 + b01 * c00x + b00 * c0px) + 2 * b00 * g_8;
        double g_24 = 1;
        double g_25 = c00y;
        double g_26 = c00y * c00y + b10;
        double g_27 = c00y + yiyj;
        double g_28 = c00y * (c00y + yiyj) + b10;
        double g_29 = c00y * (2 * b10 + g_26) + yiyj * g_26;
        double g_30 = c0py;
        double g_31 = c0py * c00y + b00;
        double g_32 = b00 * c00y + b10 * c0py + c00y * g_31;
        double g_33 = c0py * (c00y + yiyj) + b00;
        double g_34 = b00 * c00y + b10 * c0py + c00y * g_31 + yiyj * g_31;
        double g_35 = 2 * b10 * g_31 + b00 * g_26 + c00y * g_32 + yiyj * g_32;
        double g_36 = c0py + ykyl;
        double g_37 = c00y * (c0py + ykyl) + b00;
        double g_38 = b00 * c00y + b10 * c0py + c00y * g_31 + ykyl * g_26;
        double g_39 = ykyl * (yiyj + c00y) + yiyj * c0py + c0py * c00y + b00;
        double g_40 = ykyl * (yiyj * c00y + c00y * c00y + b10) + yiyj * g_31 +
                      c00y * g_31 + b10 * c0py + b00 * c00y;
        double g_41 = ykyl * (yiyj * g_26 + c00y * g_26 + 2 * b10 * c00y) +
                      yiyj * g_32 + c00y * g_32 + 2 * b10 * g_31 + b00 * g_26;
        double g_42 = c0py * (c0py + ykyl) + b01;
        double g_43 = b00 * c0py + b01 * c00y + c0py * g_31 + ykyl * g_31;
        double g_44 = ykyl * g_32 +
                      c00y * (c0py * g_31 + b01 * c00y + b00 * c0py) +
                      b10 * (c0py * c0py + b01) + 2 * b00 * g_31;
        double g_45 = ykyl * (yiyj * c0py + c0py * c00y + b00) +
                      yiyj * (c0py * c0py + b01) + c0py * g_31 + b01 * c00y +
                      b00 * c0py;
        double g_46 =
            ykyl * (yiyj * g_31 + c00y * g_31 + b10 * c0py + b00 * c00y) +
            yiyj * (c0py * g_31 + b01 * c00y + b00 * c0py) +
            c00y * (c0py * g_31 + b01 * c00y + b00 * c0py) +
            b10 * (c0py * c0py + b01) + 2 * b00 * g_31;
        double g_47 =
            ykyl * (yiyj * g_32 + c00y * g_32 + 2 * b10 * g_31 + b00 * g_26) +
            yiyj * (c00y * (c0py * g_31 + b01 * c00y + b00 * c0py) +
                       b10 * (c0py * c0py + b01) + 2 * b00 * g_31) +
            c00y * (c00y * (c0py * g_31 + b01 * c00y + b00 * c0py) +
                       b10 * (c0py * c0py + b01) + 2 * b00 * g_31) +
            2 * b10 * (c0py * g_31 + b01 * c00y + b00 * c0py) + 2 * b00 * g_32;
        double g_48 = weight0 * fac;
        double g_49 = c00z * g_48;
        double g_50 = b10 * g_48 + c00z * g_49;
        double g_51 = g_48 * (c00z + zizj);
        double g_52 = b10 * g_48 + c00z * g_49 + zizj * g_49;
        double g_53 = 2 * b10 * g_49 + c00z * g_50 + zizj * g_50;
        double g_54 = c0pz * g_48;
        double g_55 = b00 * g_48 + c0pz * g_49;
        double g_56 = b00 * g_49 + b10 * g_54 + c00z * g_55;
        double g_57 = b00 * g_48 + c0pz * g_49 + zizj * g_54;
        double g_58 = b00 * g_49 + b10 * g_54 + c00z * g_55 + zizj * g_55;
        double g_59 = 2 * b10 * g_55 + b00 * g_50 + c00z * g_56 + zizj * g_56;
        double g_60 = g_48 * (c0pz + zkzl);
        double g_61 = b00 * g_48 + c0pz * g_49 + zkzl * g_49;
        double g_62 = b00 * g_49 + b10 * g_54 + c00z * g_55 + zkzl * g_50;
        double g_63 = zkzl * (zizj * g_48 + c00z * g_48) + zizj * g_54 +
                      c0pz * g_49 + b00 * g_48;
        double g_64 = zkzl * (zizj * g_49 + c00z * g_49 + b10 * g_48) +
                      zizj * g_55 + c00z * g_55 + b10 * g_54 + b00 * g_49;
        double g_65 = zkzl * (zizj * g_50 + c00z * g_50 + 2 * b10 * g_49) +
                      zizj * g_56 + c00z * g_56 + 2 * b10 * g_55 + b00 * g_50;
        double g_66 = b01 * g_48 + c0pz * g_54 + zkzl * g_54;
        double g_67 = b00 * g_54 + b01 * g_49 + c0pz * g_55 + zkzl * g_55;
        double g_68 = zkzl * g_56 +
                      c00z * (c0pz * g_55 + b01 * g_49 + b00 * g_54) +
                      b10 * (c0pz * g_54 + b01 * g_48) + 2 * b00 * g_55;
        double g_69 = zkzl * (zizj * g_54 + c0pz * g_49 + b00 * g_48) +
                      zizj * (c0pz * g_54 + b01 * g_48) + c0pz * g_55 +
                      b01 * g_49 + b00 * g_54;
        double g_70 =
            zkzl * (zizj * g_55 + c00z * g_55 + b10 * g_54 + b00 * g_49) +
            zizj * (c0pz * g_55 + b01 * g_49 + b00 * g_54) +
            c00z * (c0pz * g_55 + b01 * g_49 + b00 * g_54) +
            b10 * (c0pz * g_54 + b01 * g_48) + 2 * b00 * g_55;
        double g_71 =
            zkzl * (zizj * g_56 + c00z * g_56 + 2 * b10 * g_55 + b00 * g_50) +
            zizj * (c00z * (c0pz * g_55 + b01 * g_49 + b00 * g_54) +
                       b10 * (c0pz * g_54 + b01 * g_48) + 2 * b00 * g_55) +
            c00z * (c00z * (c0pz * g_55 + b01 * g_49 + b00 * g_54) +
                       b10 * (c0pz * g_54 + b01 * g_48) + 2 * b00 * g_55) +
            2 * b10 * (c0pz * g_55 + b01 * g_49 + b00 * g_54) + 2 * b00 * g_56;
        gout0 += g_23 * g_24 * g_48;
        gout1 += g_22 * g_25 * g_48;
        gout2 += g_22 * g_24 * g_49;
        gout3 += g_21 * g_26 * g_48;
        gout4 += g_21 * g_25 * g_49;
        gout5 += g_21 * g_24 * g_50;
        gout6 += g_20 * g_27 * g_48;
        gout7 += g_19 * g_28 * g_48;
        gout8 += g_19 * g_27 * g_49;
        gout9 += g_18 * g_29 * g_48;
        gout10 += g_18 * g_28 * g_49;
        gout11 += g_18 * g_27 * g_50;
        gout12 += g_20 * g_24 * g_51;
        gout13 += g_19 * g_25 * g_51;
        gout14 += g_19 * g_24 * g_52;
        gout15 += g_18 * g_26 * g_51;
        gout16 += g_18 * g_25 * g_52;
        gout17 += g_18 * g_24 * g_53;
        gout18 += g_17 * g_30 * g_48;
        gout19 += g_16 * g_31 * g_48;
        gout20 += g_16 * g_30 * g_49;
        gout21 += g_15 * g_32 * g_48;
        gout22 += g_15 * g_31 * g_49;
        gout23 += g_15 * g_30 * g_50;
        gout24 += g_14 * g_33 * g_48;
        gout25 += g_13 * g_34 * g_48;
        gout26 += g_13 * g_33 * g_49;
        gout27 += g_12 * g_35 * g_48;
        gout28 += g_12 * g_34 * g_49;
        gout29 += g_12 * g_33 * g_50;
        gout30 += g_14 * g_30 * g_51;
        gout31 += g_13 * g_31 * g_51;
        gout32 += g_13 * g_30 * g_52;
        gout33 += g_12 * g_32 * g_51;
        gout34 += g_12 * g_31 * g_52;
        gout35 += g_12 * g_30 * g_53;
        gout36 += g_17 * g_24 * g_54;
        gout37 += g_16 * g_25 * g_54;
        gout38 += g_16 * g_24 * g_55;
        gout39 += g_15 * g_26 * g_54;
        gout40 += g_15 * g_25 * g_55;
        gout41 += g_15 * g_24 * g_56;
        gout42 += g_14 * g_27 * g_54;
        gout43 += g_13 * g_28 * g_54;
        gout44 += g_13 * g_27 * g_55;
        gout45 += g_12 * g_29 * g_54;
        gout46 += g_12 * g_28 * g_55;
        gout47 += g_12 * g_27 * g_56;
        gout48 += g_14 * g_24 * g_57;
        gout49 += g_13 * g_25 * g_57;
        gout50 += g_13 * g_24 * g_58;
        gout51 += g_12 * g_26 * g_57;
        gout52 += g_12 * g_25 * g_58;
        gout53 += g_12 * g_24 * g_59;
        gout54 += g_11 * g_36 * g_48;
        gout55 += g_10 * g_37 * g_48;
        gout56 += g_10 * g_36 * g_49;
        gout57 += g_9 * g_38 * g_48;
        gout58 += g_9 * g_37 * g_49;
        gout59 += g_9 * g_36 * g_50;
        gout60 += g_8 * g_39 * g_48;
        gout61 += g_7 * g_40 * g_48;
        gout62 += g_7 * g_39 * g_49;
        gout63 += g_6 * g_41 * g_48;
        gout64 += g_6 * g_40 * g_49;
        gout65 += g_6 * g_39 * g_50;
        gout66 += g_8 * g_36 * g_51;
        gout67 += g_7 * g_37 * g_51;
        gout68 += g_7 * g_36 * g_52;
        gout69 += g_6 * g_38 * g_51;
        gout70 += g_6 * g_37 * g_52;
        gout71 += g_6 * g_36 * g_53;
        gout72 += g_5 * g_42 * g_48;
        gout73 += g_4 * g_43 * g_48;
        gout74 += g_4 * g_42 * g_49;
        gout75 += g_3 * g_44 * g_48;
        gout76 += g_3 * g_43 * g_49;
        gout77 += g_3 * g_42 * g_50;
        gout78 += g_2 * g_45 * g_48;
        gout79 += g_1 * g_46 * g_48;
        gout80 += g_1 * g_45 * g_49;
        gout81 += g_0 * g_47 * g_48;
        gout82 += g_0 * g_46 * g_49;
        gout83 += g_0 * g_45 * g_50;
        gout84 += g_2 * g_42 * g_51;
        gout85 += g_1 * g_43 * g_51;
        gout86 += g_1 * g_42 * g_52;
        gout87 += g_0 * g_44 * g_51;
        gout88 += g_0 * g_43 * g_52;
        gout89 += g_0 * g_42 * g_53;
        gout90 += g_5 * g_36 * g_54;
        gout91 += g_4 * g_37 * g_54;
        gout92 += g_4 * g_36 * g_55;
        gout93 += g_3 * g_38 * g_54;
        gout94 += g_3 * g_37 * g_55;
        gout95 += g_3 * g_36 * g_56;
        gout96 += g_2 * g_39 * g_54;
        gout97 += g_1 * g_40 * g_54;
        gout98 += g_1 * g_39 * g_55;
        gout99 += g_0 * g_41 * g_54;
        gout100 += g_0 * g_40 * g_55;
        gout101 += g_0 * g_39 * g_56;
        gout102 += g_2 * g_36 * g_57;
        gout103 += g_1 * g_37 * g_57;
        gout104 += g_1 * g_36 * g_58;
        gout105 += g_0 * g_38 * g_57;
        gout106 += g_0 * g_37 * g_58;
        gout107 += g_0 * g_36 * g_59;
        gout108 += g_11 * g_24 * g_60;
        gout109 += g_10 * g_25 * g_60;
        gout110 += g_10 * g_24 * g_61;
        gout111 += g_9 * g_26 * g_60;
        gout112 += g_9 * g_25 * g_61;
        gout113 += g_9 * g_24 * g_62;
        gout114 += g_8 * g_27 * g_60;
        gout115 += g_7 * g_28 * g_60;
        gout116 += g_7 * g_27 * g_61;
        gout117 += g_6 * g_29 * g_60;
        gout118 += g_6 * g_28 * g_61;
        gout119 += g_6 * g_27 * g_62;
        gout120 += g_8 * g_24 * g_63;
        gout121 += g_7 * g_25 * g_63;
        gout122 += g_7 * g_24 * g_64;
        gout123 += g_6 * g_26 * g_63;
        gout124 += g_6 * g_25 * g_64;
        gout125 += g_6 * g_24 * g_65;
        gout126 += g_5 * g_30 * g_60;
        gout127 += g_4 * g_31 * g_60;
        gout128 += g_4 * g_30 * g_61;
        gout129 += g_3 * g_32 * g_60;
        gout130 += g_3 * g_31 * g_61;
        gout131 += g_3 * g_30 * g_62;
        gout132 += g_2 * g_33 * g_60;
        gout133 += g_1 * g_34 * g_60;
        gout134 += g_1 * g_33 * g_61;
        gout135 += g_0 * g_35 * g_60;
        gout136 += g_0 * g_34 * g_61;
        gout137 += g_0 * g_33 * g_62;
        gout138 += g_2 * g_30 * g_63;
        gout139 += g_1 * g_31 * g_63;
        gout140 += g_1 * g_30 * g_64;
        gout141 += g_0 * g_32 * g_63;
        gout142 += g_0 * g_31 * g_64;
        gout143 += g_0 * g_30 * g_65;
        gout144 += g_5 * g_24 * g_66;
        gout145 += g_4 * g_25 * g_66;
        gout146 += g_4 * g_24 * g_67;
        gout147 += g_3 * g_26 * g_66;
        gout148 += g_3 * g_25 * g_67;
        gout149 += g_3 * g_24 * g_68;
        gout150 += g_2 * g_27 * g_66;
        gout151 += g_1 * g_28 * g_66;
        gout152 += g_1 * g_27 * g_67;
        gout153 += g_0 * g_29 * g_66;
        gout154 += g_0 * g_28 * g_67;
        gout155 += g_0 * g_27 * g_68;
        gout156 += g_2 * g_24 * g_69;
        gout157 += g_1 * g_25 * g_69;
        gout158 += g_1 * g_24 * g_70;
        gout159 += g_0 * g_26 * g_69;
        gout160 += g_0 * g_25 * g_70;
        gout161 += g_0 * g_24 * g_71;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        gout81 = reduce(gout81);
        gout82 = reduce(gout82);
        gout83 = reduce(gout83);
        gout84 = reduce(gout84);
        gout85 = reduce(gout85);
        gout86 = reduce(gout86);
        gout87 = reduce(gout87);
        gout88 = reduce(gout88);
        gout89 = reduce(gout89);
        gout90 = reduce(gout90);
        gout91 = reduce(gout91);
        gout92 = reduce(gout92);
        gout93 = reduce(gout93);
        gout94 = reduce(gout94);
        gout95 = reduce(gout95);
        gout96 = reduce(gout96);
        gout97 = reduce(gout97);
        gout98 = reduce(gout98);
        gout99 = reduce(gout99);
        gout100 = reduce(gout100);
        gout101 = reduce(gout101);
        gout102 = reduce(gout102);
        gout103 = reduce(gout103);
        gout104 = reduce(gout104);
        gout105 = reduce(gout105);
        gout106 = reduce(gout106);
        gout107 = reduce(gout107);
        gout108 = reduce(gout108);
        gout109 = reduce(gout109);
        gout110 = reduce(gout110);
        gout111 = reduce(gout111);
        gout112 = reduce(gout112);
        gout113 = reduce(gout113);
        gout114 = reduce(gout114);
        gout115 = reduce(gout115);
        gout116 = reduce(gout116);
        gout117 = reduce(gout117);
        gout118 = reduce(gout118);
        gout119 = reduce(gout119);
        gout120 = reduce(gout120);
        gout121 = reduce(gout121);
        gout122 = reduce(gout122);
        gout123 = reduce(gout123);
        gout124 = reduce(gout124);
        gout125 = reduce(gout125);
        gout126 = reduce(gout126);
        gout127 = reduce(gout127);
        gout128 = reduce(gout128);
        gout129 = reduce(gout129);
        gout130 = reduce(gout130);
        gout131 = reduce(gout131);
        gout132 = reduce(gout132);
        gout133 = reduce(gout133);
        gout134 = reduce(gout134);
        gout135 = reduce(gout135);
        gout136 = reduce(gout136);
        gout137 = reduce(gout137);
        gout138 = reduce(gout138);
        gout139 = reduce(gout139);
        gout140 = reduce(gout140);
        gout141 = reduce(gout141);
        gout142 = reduce(gout142);
        gout143 = reduce(gout143);
        gout144 = reduce(gout144);
        gout145 = reduce(gout145);
        gout146 = reduce(gout146);
        gout147 = reduce(gout147);
        gout148 = reduce(gout148);
        gout149 = reduce(gout149);
        gout150 = reduce(gout150);
        gout151 = reduce(gout151);
        gout152 = reduce(gout152);
        gout153 = reduce(gout153);
        gout154 = reduce(gout154);
        gout155 = reduce(gout155);
        gout156 = reduce(gout156);
        gout157 = reduce(gout157);
        gout158 = reduce(gout158);
        gout159 = reduce(gout159);
        gout160 = reduce(gout160);
        gout161 = reduce(gout161);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 1 * jstride, gout6);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout7);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout8);
    atomicAdd(peri + 3 * istride + 1 * jstride, gout9);
    atomicAdd(peri + 4 * istride + 1 * jstride, gout10);
    atomicAdd(peri + 5 * istride + 1 * jstride, gout11);
    atomicAdd(peri + 2 * jstride, gout12);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout13);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout14);
    atomicAdd(peri + 3 * istride + 2 * jstride, gout15);
    atomicAdd(peri + 4 * istride + 2 * jstride, gout16);
    atomicAdd(peri + 5 * istride + 2 * jstride, gout17);
    atomicAdd(peri + 1 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout20);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout21);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout22);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout23);
    atomicAdd(peri + 1 * jstride + 1 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * kstride, gout26);
    atomicAdd(peri + 3 * istride + 1 * jstride + 1 * kstride, gout27);
    atomicAdd(peri + 4 * istride + 1 * jstride + 1 * kstride, gout28);
    atomicAdd(peri + 5 * istride + 1 * jstride + 1 * kstride, gout29);
    atomicAdd(peri + 2 * jstride + 1 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * kstride, gout32);
    atomicAdd(peri + 3 * istride + 2 * jstride + 1 * kstride, gout33);
    atomicAdd(peri + 4 * istride + 2 * jstride + 1 * kstride, gout34);
    atomicAdd(peri + 5 * istride + 2 * jstride + 1 * kstride, gout35);
    atomicAdd(peri + 2 * kstride, gout36);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout37);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout38);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout39);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout40);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout41);
    atomicAdd(peri + 1 * jstride + 2 * kstride, gout42);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * kstride, gout43);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * kstride, gout44);
    atomicAdd(peri + 3 * istride + 1 * jstride + 2 * kstride, gout45);
    atomicAdd(peri + 4 * istride + 1 * jstride + 2 * kstride, gout46);
    atomicAdd(peri + 5 * istride + 1 * jstride + 2 * kstride, gout47);
    atomicAdd(peri + 2 * jstride + 2 * kstride, gout48);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * kstride, gout49);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * kstride, gout50);
    atomicAdd(peri + 3 * istride + 2 * jstride + 2 * kstride, gout51);
    atomicAdd(peri + 4 * istride + 2 * jstride + 2 * kstride, gout52);
    atomicAdd(peri + 5 * istride + 2 * jstride + 2 * kstride, gout53);
    atomicAdd(peri + 1 * lstride, gout54);
    atomicAdd(peri + 1 * istride + 1 * lstride, gout55);
    atomicAdd(peri + 2 * istride + 1 * lstride, gout56);
    atomicAdd(peri + 3 * istride + 1 * lstride, gout57);
    atomicAdd(peri + 4 * istride + 1 * lstride, gout58);
    atomicAdd(peri + 5 * istride + 1 * lstride, gout59);
    atomicAdd(peri + 1 * jstride + 1 * lstride, gout60);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * lstride, gout61);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * lstride, gout62);
    atomicAdd(peri + 3 * istride + 1 * jstride + 1 * lstride, gout63);
    atomicAdd(peri + 4 * istride + 1 * jstride + 1 * lstride, gout64);
    atomicAdd(peri + 5 * istride + 1 * jstride + 1 * lstride, gout65);
    atomicAdd(peri + 2 * jstride + 1 * lstride, gout66);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * lstride, gout67);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * lstride, gout68);
    atomicAdd(peri + 3 * istride + 2 * jstride + 1 * lstride, gout69);
    atomicAdd(peri + 4 * istride + 2 * jstride + 1 * lstride, gout70);
    atomicAdd(peri + 5 * istride + 2 * jstride + 1 * lstride, gout71);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout72);
    atomicAdd(peri + 1 * istride + 1 * kstride + 1 * lstride, gout73);
    atomicAdd(peri + 2 * istride + 1 * kstride + 1 * lstride, gout74);
    atomicAdd(peri + 3 * istride + 1 * kstride + 1 * lstride, gout75);
    atomicAdd(peri + 4 * istride + 1 * kstride + 1 * lstride, gout76);
    atomicAdd(peri + 5 * istride + 1 * kstride + 1 * lstride, gout77);
    atomicAdd(peri + 1 * jstride + 1 * kstride + 1 * lstride, gout78);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 1 * kstride + 1 * lstride, gout79);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 1 * kstride + 1 * lstride, gout80);
    atomicAdd(
        peri + 3 * istride + 1 * jstride + 1 * kstride + 1 * lstride, gout81);
    atomicAdd(
        peri + 4 * istride + 1 * jstride + 1 * kstride + 1 * lstride, gout82);
    atomicAdd(
        peri + 5 * istride + 1 * jstride + 1 * kstride + 1 * lstride, gout83);
    atomicAdd(peri + 2 * jstride + 1 * kstride + 1 * lstride, gout84);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 1 * kstride + 1 * lstride, gout85);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 1 * kstride + 1 * lstride, gout86);
    atomicAdd(
        peri + 3 * istride + 2 * jstride + 1 * kstride + 1 * lstride, gout87);
    atomicAdd(
        peri + 4 * istride + 2 * jstride + 1 * kstride + 1 * lstride, gout88);
    atomicAdd(
        peri + 5 * istride + 2 * jstride + 1 * kstride + 1 * lstride, gout89);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout90);
    atomicAdd(peri + 1 * istride + 2 * kstride + 1 * lstride, gout91);
    atomicAdd(peri + 2 * istride + 2 * kstride + 1 * lstride, gout92);
    atomicAdd(peri + 3 * istride + 2 * kstride + 1 * lstride, gout93);
    atomicAdd(peri + 4 * istride + 2 * kstride + 1 * lstride, gout94);
    atomicAdd(peri + 5 * istride + 2 * kstride + 1 * lstride, gout95);
    atomicAdd(peri + 1 * jstride + 2 * kstride + 1 * lstride, gout96);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 2 * kstride + 1 * lstride, gout97);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 2 * kstride + 1 * lstride, gout98);
    atomicAdd(
        peri + 3 * istride + 1 * jstride + 2 * kstride + 1 * lstride, gout99);
    atomicAdd(
        peri + 4 * istride + 1 * jstride + 2 * kstride + 1 * lstride, gout100);
    atomicAdd(
        peri + 5 * istride + 1 * jstride + 2 * kstride + 1 * lstride, gout101);
    atomicAdd(peri + 2 * jstride + 2 * kstride + 1 * lstride, gout102);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 2 * kstride + 1 * lstride, gout103);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 2 * kstride + 1 * lstride, gout104);
    atomicAdd(
        peri + 3 * istride + 2 * jstride + 2 * kstride + 1 * lstride, gout105);
    atomicAdd(
        peri + 4 * istride + 2 * jstride + 2 * kstride + 1 * lstride, gout106);
    atomicAdd(
        peri + 5 * istride + 2 * jstride + 2 * kstride + 1 * lstride, gout107);
    atomicAdd(peri + 2 * lstride, gout108);
    atomicAdd(peri + 1 * istride + 2 * lstride, gout109);
    atomicAdd(peri + 2 * istride + 2 * lstride, gout110);
    atomicAdd(peri + 3 * istride + 2 * lstride, gout111);
    atomicAdd(peri + 4 * istride + 2 * lstride, gout112);
    atomicAdd(peri + 5 * istride + 2 * lstride, gout113);
    atomicAdd(peri + 1 * jstride + 2 * lstride, gout114);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * lstride, gout115);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * lstride, gout116);
    atomicAdd(peri + 3 * istride + 1 * jstride + 2 * lstride, gout117);
    atomicAdd(peri + 4 * istride + 1 * jstride + 2 * lstride, gout118);
    atomicAdd(peri + 5 * istride + 1 * jstride + 2 * lstride, gout119);
    atomicAdd(peri + 2 * jstride + 2 * lstride, gout120);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * lstride, gout121);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * lstride, gout122);
    atomicAdd(peri + 3 * istride + 2 * jstride + 2 * lstride, gout123);
    atomicAdd(peri + 4 * istride + 2 * jstride + 2 * lstride, gout124);
    atomicAdd(peri + 5 * istride + 2 * jstride + 2 * lstride, gout125);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout126);
    atomicAdd(peri + 1 * istride + 1 * kstride + 2 * lstride, gout127);
    atomicAdd(peri + 2 * istride + 1 * kstride + 2 * lstride, gout128);
    atomicAdd(peri + 3 * istride + 1 * kstride + 2 * lstride, gout129);
    atomicAdd(peri + 4 * istride + 1 * kstride + 2 * lstride, gout130);
    atomicAdd(peri + 5 * istride + 1 * kstride + 2 * lstride, gout131);
    atomicAdd(peri + 1 * jstride + 1 * kstride + 2 * lstride, gout132);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 1 * kstride + 2 * lstride, gout133);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 1 * kstride + 2 * lstride, gout134);
    atomicAdd(
        peri + 3 * istride + 1 * jstride + 1 * kstride + 2 * lstride, gout135);
    atomicAdd(
        peri + 4 * istride + 1 * jstride + 1 * kstride + 2 * lstride, gout136);
    atomicAdd(
        peri + 5 * istride + 1 * jstride + 1 * kstride + 2 * lstride, gout137);
    atomicAdd(peri + 2 * jstride + 1 * kstride + 2 * lstride, gout138);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 1 * kstride + 2 * lstride, gout139);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 1 * kstride + 2 * lstride, gout140);
    atomicAdd(
        peri + 3 * istride + 2 * jstride + 1 * kstride + 2 * lstride, gout141);
    atomicAdd(
        peri + 4 * istride + 2 * jstride + 1 * kstride + 2 * lstride, gout142);
    atomicAdd(
        peri + 5 * istride + 2 * jstride + 1 * kstride + 2 * lstride, gout143);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout144);
    atomicAdd(peri + 1 * istride + 2 * kstride + 2 * lstride, gout145);
    atomicAdd(peri + 2 * istride + 2 * kstride + 2 * lstride, gout146);
    atomicAdd(peri + 3 * istride + 2 * kstride + 2 * lstride, gout147);
    atomicAdd(peri + 4 * istride + 2 * kstride + 2 * lstride, gout148);
    atomicAdd(peri + 5 * istride + 2 * kstride + 2 * lstride, gout149);
    atomicAdd(peri + 1 * jstride + 2 * kstride + 2 * lstride, gout150);
    atomicAdd(
        peri + 1 * istride + 1 * jstride + 2 * kstride + 2 * lstride, gout151);
    atomicAdd(
        peri + 2 * istride + 1 * jstride + 2 * kstride + 2 * lstride, gout152);
    atomicAdd(
        peri + 3 * istride + 1 * jstride + 2 * kstride + 2 * lstride, gout153);
    atomicAdd(
        peri + 4 * istride + 1 * jstride + 2 * kstride + 2 * lstride, gout154);
    atomicAdd(
        peri + 5 * istride + 1 * jstride + 2 * kstride + 2 * lstride, gout155);
    atomicAdd(peri + 2 * jstride + 2 * kstride + 2 * lstride, gout156);
    atomicAdd(
        peri + 1 * istride + 2 * jstride + 2 * kstride + 2 * lstride, gout157);
    atomicAdd(
        peri + 2 * istride + 2 * jstride + 2 * kstride + 2 * lstride, gout158);
    atomicAdd(
        peri + 3 * istride + 2 * jstride + 2 * kstride + 2 * lstride, gout159);
    atomicAdd(
        peri + 4 * istride + 2 * jstride + 2 * kstride + 2 * lstride, gout160);
    atomicAdd(
        peri + 5 * istride + 2 * jstride + 2 * kstride + 2 * lstride, gout161);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel2120(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x + xixj;
        double g_4 = c00x * (c00x + xixj) + b10;
        double g_5 = c00x * (2 * b10 + g_2) + xixj * g_2;
        double g_6 = c0px;
        double g_7 = c0px * c00x + b00;
        double g_8 = b00 * c00x + b10 * c0px + c00x * g_7;
        double g_9 = c0px * (c00x + xixj) + b00;
        double g_10 = b00 * c00x + b10 * c0px + c00x * g_7 + xixj * g_7;
        double g_11 = 2 * b10 * g_7 + b00 * g_2 + c00x * g_8 + xixj * g_8;
        double g_12 = c0px * c0px + b01;
        double g_13 = b00 * c0px + b01 * c00x + c0px * g_7;
        double g_14 = 2 * b00 * g_7 + b10 * g_12 + c00x * g_13;
        double g_15 = b00 * c0px + b01 * c00x + c0px * g_7 + xixj * g_12;
        double g_16 = 2 * b00 * g_7 + b10 * g_12 + c00x * g_13 + xixj * g_13;
        double g_17 = 2 * (b00 * g_8 + b10 * g_13) + c00x * g_14 + xixj * g_14;
        double g_18 = 1;
        double g_19 = c00y;
        double g_20 = c00y * c00y + b10;
        double g_21 = c00y + yiyj;
        double g_22 = c00y * (c00y + yiyj) + b10;
        double g_23 = c00y * (2 * b10 + g_20) + yiyj * g_20;
        double g_24 = c0py;
        double g_25 = c0py * c00y + b00;
        double g_26 = b00 * c00y + b10 * c0py + c00y * g_25;
        double g_27 = c0py * (c00y + yiyj) + b00;
        double g_28 = b00 * c00y + b10 * c0py + c00y * g_25 + yiyj * g_25;
        double g_29 = 2 * b10 * g_25 + b00 * g_20 + c00y * g_26 + yiyj * g_26;
        double g_30 = c0py * c0py + b01;
        double g_31 = b00 * c0py + b01 * c00y + c0py * g_25;
        double g_32 = 2 * b00 * g_25 + b10 * g_30 + c00y * g_31;
        double g_33 = b00 * c0py + b01 * c00y + c0py * g_25 + yiyj * g_30;
        double g_34 = 2 * b00 * g_25 + b10 * g_30 + c00y * g_31 + yiyj * g_31;
        double g_35 =
            2 * (b00 * g_26 + b10 * g_31) + c00y * g_32 + yiyj * g_32;
        double g_36 = weight0 * fac;
        double g_37 = c00z * g_36;
        double g_38 = b10 * g_36 + c00z * g_37;
        double g_39 = g_36 * (c00z + zizj);
        double g_40 = b10 * g_36 + c00z * g_37 + zizj * g_37;
        double g_41 = 2 * b10 * g_37 + c00z * g_38 + zizj * g_38;
        double g_42 = c0pz * g_36;
        double g_43 = b00 * g_36 + c0pz * g_37;
        double g_44 = b00 * g_37 + b10 * g_42 + c00z * g_43;
        double g_45 = b00 * g_36 + c0pz * g_37 + zizj * g_42;
        double g_46 = b00 * g_37 + b10 * g_42 + c00z * g_43 + zizj * g_43;
        double g_47 = 2 * b10 * g_43 + b00 * g_38 + c00z * g_44 + zizj * g_44;
        double g_48 = b01 * g_36 + c0pz * g_42;
        double g_49 = b00 * g_42 + b01 * g_37 + c0pz * g_43;
        double g_50 = 2 * b00 * g_43 + b10 * g_48 + c00z * g_49;
        double g_51 = b00 * g_42 + b01 * g_37 + c0pz * g_43 + zizj * g_48;
        double g_52 = 2 * b00 * g_43 + b10 * g_48 + c00z * g_49 + zizj * g_49;
        double g_53 =
            2 * (b00 * g_44 + b10 * g_49) + c00z * g_50 + zizj * g_50;
        gout0 += g_17 * g_18 * g_36;
        gout1 += g_16 * g_19 * g_36;
        gout2 += g_16 * g_18 * g_37;
        gout3 += g_15 * g_20 * g_36;
        gout4 += g_15 * g_19 * g_37;
        gout5 += g_15 * g_18 * g_38;
        gout6 += g_14 * g_21 * g_36;
        gout7 += g_13 * g_22 * g_36;
        gout8 += g_13 * g_21 * g_37;
        gout9 += g_12 * g_23 * g_36;
        gout10 += g_12 * g_22 * g_37;
        gout11 += g_12 * g_21 * g_38;
        gout12 += g_14 * g_18 * g_39;
        gout13 += g_13 * g_19 * g_39;
        gout14 += g_13 * g_18 * g_40;
        gout15 += g_12 * g_20 * g_39;
        gout16 += g_12 * g_19 * g_40;
        gout17 += g_12 * g_18 * g_41;
        gout18 += g_11 * g_24 * g_36;
        gout19 += g_10 * g_25 * g_36;
        gout20 += g_10 * g_24 * g_37;
        gout21 += g_9 * g_26 * g_36;
        gout22 += g_9 * g_25 * g_37;
        gout23 += g_9 * g_24 * g_38;
        gout24 += g_8 * g_27 * g_36;
        gout25 += g_7 * g_28 * g_36;
        gout26 += g_7 * g_27 * g_37;
        gout27 += g_6 * g_29 * g_36;
        gout28 += g_6 * g_28 * g_37;
        gout29 += g_6 * g_27 * g_38;
        gout30 += g_8 * g_24 * g_39;
        gout31 += g_7 * g_25 * g_39;
        gout32 += g_7 * g_24 * g_40;
        gout33 += g_6 * g_26 * g_39;
        gout34 += g_6 * g_25 * g_40;
        gout35 += g_6 * g_24 * g_41;
        gout36 += g_11 * g_18 * g_42;
        gout37 += g_10 * g_19 * g_42;
        gout38 += g_10 * g_18 * g_43;
        gout39 += g_9 * g_20 * g_42;
        gout40 += g_9 * g_19 * g_43;
        gout41 += g_9 * g_18 * g_44;
        gout42 += g_8 * g_21 * g_42;
        gout43 += g_7 * g_22 * g_42;
        gout44 += g_7 * g_21 * g_43;
        gout45 += g_6 * g_23 * g_42;
        gout46 += g_6 * g_22 * g_43;
        gout47 += g_6 * g_21 * g_44;
        gout48 += g_8 * g_18 * g_45;
        gout49 += g_7 * g_19 * g_45;
        gout50 += g_7 * g_18 * g_46;
        gout51 += g_6 * g_20 * g_45;
        gout52 += g_6 * g_19 * g_46;
        gout53 += g_6 * g_18 * g_47;
        gout54 += g_5 * g_30 * g_36;
        gout55 += g_4 * g_31 * g_36;
        gout56 += g_4 * g_30 * g_37;
        gout57 += g_3 * g_32 * g_36;
        gout58 += g_3 * g_31 * g_37;
        gout59 += g_3 * g_30 * g_38;
        gout60 += g_2 * g_33 * g_36;
        gout61 += g_1 * g_34 * g_36;
        gout62 += g_1 * g_33 * g_37;
        gout63 += g_0 * g_35 * g_36;
        gout64 += g_0 * g_34 * g_37;
        gout65 += g_0 * g_33 * g_38;
        gout66 += g_2 * g_30 * g_39;
        gout67 += g_1 * g_31 * g_39;
        gout68 += g_1 * g_30 * g_40;
        gout69 += g_0 * g_32 * g_39;
        gout70 += g_0 * g_31 * g_40;
        gout71 += g_0 * g_30 * g_41;
        gout72 += g_5 * g_24 * g_42;
        gout73 += g_4 * g_25 * g_42;
        gout74 += g_4 * g_24 * g_43;
        gout75 += g_3 * g_26 * g_42;
        gout76 += g_3 * g_25 * g_43;
        gout77 += g_3 * g_24 * g_44;
        gout78 += g_2 * g_27 * g_42;
        gout79 += g_1 * g_28 * g_42;
        gout80 += g_1 * g_27 * g_43;
        gout81 += g_0 * g_29 * g_42;
        gout82 += g_0 * g_28 * g_43;
        gout83 += g_0 * g_27 * g_44;
        gout84 += g_2 * g_24 * g_45;
        gout85 += g_1 * g_25 * g_45;
        gout86 += g_1 * g_24 * g_46;
        gout87 += g_0 * g_26 * g_45;
        gout88 += g_0 * g_25 * g_46;
        gout89 += g_0 * g_24 * g_47;
        gout90 += g_5 * g_18 * g_48;
        gout91 += g_4 * g_19 * g_48;
        gout92 += g_4 * g_18 * g_49;
        gout93 += g_3 * g_20 * g_48;
        gout94 += g_3 * g_19 * g_49;
        gout95 += g_3 * g_18 * g_50;
        gout96 += g_2 * g_21 * g_48;
        gout97 += g_1 * g_22 * g_48;
        gout98 += g_1 * g_21 * g_49;
        gout99 += g_0 * g_23 * g_48;
        gout100 += g_0 * g_22 * g_49;
        gout101 += g_0 * g_21 * g_50;
        gout102 += g_2 * g_18 * g_51;
        gout103 += g_1 * g_19 * g_51;
        gout104 += g_1 * g_18 * g_52;
        gout105 += g_0 * g_20 * g_51;
        gout106 += g_0 * g_19 * g_52;
        gout107 += g_0 * g_18 * g_53;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        gout81 = reduce(gout81);
        gout82 = reduce(gout82);
        gout83 = reduce(gout83);
        gout84 = reduce(gout84);
        gout85 = reduce(gout85);
        gout86 = reduce(gout86);
        gout87 = reduce(gout87);
        gout88 = reduce(gout88);
        gout89 = reduce(gout89);
        gout90 = reduce(gout90);
        gout91 = reduce(gout91);
        gout92 = reduce(gout92);
        gout93 = reduce(gout93);
        gout94 = reduce(gout94);
        gout95 = reduce(gout95);
        gout96 = reduce(gout96);
        gout97 = reduce(gout97);
        gout98 = reduce(gout98);
        gout99 = reduce(gout99);
        gout100 = reduce(gout100);
        gout101 = reduce(gout101);
        gout102 = reduce(gout102);
        gout103 = reduce(gout103);
        gout104 = reduce(gout104);
        gout105 = reduce(gout105);
        gout106 = reduce(gout106);
        gout107 = reduce(gout107);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 1 * jstride, gout6);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout7);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout8);
    atomicAdd(peri + 3 * istride + 1 * jstride, gout9);
    atomicAdd(peri + 4 * istride + 1 * jstride, gout10);
    atomicAdd(peri + 5 * istride + 1 * jstride, gout11);
    atomicAdd(peri + 2 * jstride, gout12);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout13);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout14);
    atomicAdd(peri + 3 * istride + 2 * jstride, gout15);
    atomicAdd(peri + 4 * istride + 2 * jstride, gout16);
    atomicAdd(peri + 5 * istride + 2 * jstride, gout17);
    atomicAdd(peri + 1 * kstride, gout18);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout19);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout20);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout21);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout22);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout23);
    atomicAdd(peri + 1 * jstride + 1 * kstride, gout24);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * kstride, gout25);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * kstride, gout26);
    atomicAdd(peri + 3 * istride + 1 * jstride + 1 * kstride, gout27);
    atomicAdd(peri + 4 * istride + 1 * jstride + 1 * kstride, gout28);
    atomicAdd(peri + 5 * istride + 1 * jstride + 1 * kstride, gout29);
    atomicAdd(peri + 2 * jstride + 1 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * kstride, gout32);
    atomicAdd(peri + 3 * istride + 2 * jstride + 1 * kstride, gout33);
    atomicAdd(peri + 4 * istride + 2 * jstride + 1 * kstride, gout34);
    atomicAdd(peri + 5 * istride + 2 * jstride + 1 * kstride, gout35);
    atomicAdd(peri + 2 * kstride, gout36);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout37);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout38);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout39);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout40);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout41);
    atomicAdd(peri + 1 * jstride + 2 * kstride, gout42);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * kstride, gout43);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * kstride, gout44);
    atomicAdd(peri + 3 * istride + 1 * jstride + 2 * kstride, gout45);
    atomicAdd(peri + 4 * istride + 1 * jstride + 2 * kstride, gout46);
    atomicAdd(peri + 5 * istride + 1 * jstride + 2 * kstride, gout47);
    atomicAdd(peri + 2 * jstride + 2 * kstride, gout48);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * kstride, gout49);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * kstride, gout50);
    atomicAdd(peri + 3 * istride + 2 * jstride + 2 * kstride, gout51);
    atomicAdd(peri + 4 * istride + 2 * jstride + 2 * kstride, gout52);
    atomicAdd(peri + 5 * istride + 2 * jstride + 2 * kstride, gout53);
    atomicAdd(peri + 3 * kstride, gout54);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout55);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout56);
    atomicAdd(peri + 3 * istride + 3 * kstride, gout57);
    atomicAdd(peri + 4 * istride + 3 * kstride, gout58);
    atomicAdd(peri + 5 * istride + 3 * kstride, gout59);
    atomicAdd(peri + 1 * jstride + 3 * kstride, gout60);
    atomicAdd(peri + 1 * istride + 1 * jstride + 3 * kstride, gout61);
    atomicAdd(peri + 2 * istride + 1 * jstride + 3 * kstride, gout62);
    atomicAdd(peri + 3 * istride + 1 * jstride + 3 * kstride, gout63);
    atomicAdd(peri + 4 * istride + 1 * jstride + 3 * kstride, gout64);
    atomicAdd(peri + 5 * istride + 1 * jstride + 3 * kstride, gout65);
    atomicAdd(peri + 2 * jstride + 3 * kstride, gout66);
    atomicAdd(peri + 1 * istride + 2 * jstride + 3 * kstride, gout67);
    atomicAdd(peri + 2 * istride + 2 * jstride + 3 * kstride, gout68);
    atomicAdd(peri + 3 * istride + 2 * jstride + 3 * kstride, gout69);
    atomicAdd(peri + 4 * istride + 2 * jstride + 3 * kstride, gout70);
    atomicAdd(peri + 5 * istride + 2 * jstride + 3 * kstride, gout71);
    atomicAdd(peri + 4 * kstride, gout72);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout73);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout74);
    atomicAdd(peri + 3 * istride + 4 * kstride, gout75);
    atomicAdd(peri + 4 * istride + 4 * kstride, gout76);
    atomicAdd(peri + 5 * istride + 4 * kstride, gout77);
    atomicAdd(peri + 1 * jstride + 4 * kstride, gout78);
    atomicAdd(peri + 1 * istride + 1 * jstride + 4 * kstride, gout79);
    atomicAdd(peri + 2 * istride + 1 * jstride + 4 * kstride, gout80);
    atomicAdd(peri + 3 * istride + 1 * jstride + 4 * kstride, gout81);
    atomicAdd(peri + 4 * istride + 1 * jstride + 4 * kstride, gout82);
    atomicAdd(peri + 5 * istride + 1 * jstride + 4 * kstride, gout83);
    atomicAdd(peri + 2 * jstride + 4 * kstride, gout84);
    atomicAdd(peri + 1 * istride + 2 * jstride + 4 * kstride, gout85);
    atomicAdd(peri + 2 * istride + 2 * jstride + 4 * kstride, gout86);
    atomicAdd(peri + 3 * istride + 2 * jstride + 4 * kstride, gout87);
    atomicAdd(peri + 4 * istride + 2 * jstride + 4 * kstride, gout88);
    atomicAdd(peri + 5 * istride + 2 * jstride + 4 * kstride, gout89);
    atomicAdd(peri + 5 * kstride, gout90);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout91);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout92);
    atomicAdd(peri + 3 * istride + 5 * kstride, gout93);
    atomicAdd(peri + 4 * istride + 5 * kstride, gout94);
    atomicAdd(peri + 5 * istride + 5 * kstride, gout95);
    atomicAdd(peri + 1 * jstride + 5 * kstride, gout96);
    atomicAdd(peri + 1 * istride + 1 * jstride + 5 * kstride, gout97);
    atomicAdd(peri + 2 * istride + 1 * jstride + 5 * kstride, gout98);
    atomicAdd(peri + 3 * istride + 1 * jstride + 5 * kstride, gout99);
    atomicAdd(peri + 4 * istride + 1 * jstride + 5 * kstride, gout100);
    atomicAdd(peri + 5 * istride + 1 * jstride + 5 * kstride, gout101);
    atomicAdd(peri + 2 * jstride + 5 * kstride, gout102);
    atomicAdd(peri + 1 * istride + 2 * jstride + 5 * kstride, gout103);
    atomicAdd(peri + 2 * istride + 2 * jstride + 5 * kstride, gout104);
    atomicAdd(peri + 3 * istride + 2 * jstride + 5 * kstride, gout105);
    atomicAdd(peri + 4 * istride + 2 * jstride + 5 * kstride, gout106);
    atomicAdd(peri + 5 * istride + 2 * jstride + 5 * kstride, gout107);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel2200(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x + xixj;
        double g_4 = c00x * (c00x + xixj) + b10;
        double g_5 = c00x * (2 * b10 + g_2) + xixj * g_2;
        double g_6 = xixj * (xixj + c00x) + xixj * c00x + c00x * c00x + b10;
        double g_7 = xixj * (xixj * c00x + c00x * c00x + b10) + xixj * g_2 +
                     c00x * g_2 + 2 * b10 * c00x;
        double g_8 = xixj * (xixj * g_2 + c00x * g_2 + 2 * b10 * c00x) +
                     xixj * (c00x * g_2 + 2 * b10 * c00x) +
                     c00x * (c00x * g_2 + 2 * b10 * c00x) + 3 * b10 * g_2;
        double g_9 = 1;
        double g_10 = c00y;
        double g_11 = c00y * c00y + b10;
        double g_12 = c00y + yiyj;
        double g_13 = c00y * (c00y + yiyj) + b10;
        double g_14 = c00y * (2 * b10 + g_11) + yiyj * g_11;
        double g_15 = yiyj * (yiyj + c00y) + yiyj * c00y + c00y * c00y + b10;
        double g_16 = yiyj * (yiyj * c00y + c00y * c00y + b10) + yiyj * g_11 +
                      c00y * g_11 + 2 * b10 * c00y;
        double g_17 = yiyj * (yiyj * g_11 + c00y * g_11 + 2 * b10 * c00y) +
                      yiyj * (c00y * g_11 + 2 * b10 * c00y) +
                      c00y * (c00y * g_11 + 2 * b10 * c00y) + 3 * b10 * g_11;
        double g_18 = weight0 * fac;
        double g_19 = c00z * g_18;
        double g_20 = b10 * g_18 + c00z * g_19;
        double g_21 = g_18 * (c00z + zizj);
        double g_22 = b10 * g_18 + c00z * g_19 + zizj * g_19;
        double g_23 = 2 * b10 * g_19 + c00z * g_20 + zizj * g_20;
        double g_24 = zizj * (zizj * g_18 + c00z * g_18) + zizj * g_19 +
                      c00z * g_19 + b10 * g_18;
        double g_25 = zizj * (zizj * g_19 + c00z * g_19 + b10 * g_18) +
                      zizj * g_20 + c00z * g_20 + 2 * b10 * g_19;
        double g_26 = zizj * (zizj * g_20 + c00z * g_20 + 2 * b10 * g_19) +
                      zizj * (c00z * g_20 + 2 * b10 * g_19) +
                      c00z * (c00z * g_20 + 2 * b10 * g_19) + 3 * b10 * g_20;
        gout0 += g_8 * g_9 * g_18;
        gout1 += g_7 * g_10 * g_18;
        gout2 += g_7 * g_9 * g_19;
        gout3 += g_6 * g_11 * g_18;
        gout4 += g_6 * g_10 * g_19;
        gout5 += g_6 * g_9 * g_20;
        gout6 += g_5 * g_12 * g_18;
        gout7 += g_4 * g_13 * g_18;
        gout8 += g_4 * g_12 * g_19;
        gout9 += g_3 * g_14 * g_18;
        gout10 += g_3 * g_13 * g_19;
        gout11 += g_3 * g_12 * g_20;
        gout12 += g_5 * g_9 * g_21;
        gout13 += g_4 * g_10 * g_21;
        gout14 += g_4 * g_9 * g_22;
        gout15 += g_3 * g_11 * g_21;
        gout16 += g_3 * g_10 * g_22;
        gout17 += g_3 * g_9 * g_23;
        gout18 += g_2 * g_15 * g_18;
        gout19 += g_1 * g_16 * g_18;
        gout20 += g_1 * g_15 * g_19;
        gout21 += g_0 * g_17 * g_18;
        gout22 += g_0 * g_16 * g_19;
        gout23 += g_0 * g_15 * g_20;
        gout24 += g_2 * g_12 * g_21;
        gout25 += g_1 * g_13 * g_21;
        gout26 += g_1 * g_12 * g_22;
        gout27 += g_0 * g_14 * g_21;
        gout28 += g_0 * g_13 * g_22;
        gout29 += g_0 * g_12 * g_23;
        gout30 += g_2 * g_9 * g_24;
        gout31 += g_1 * g_10 * g_24;
        gout32 += g_1 * g_9 * g_25;
        gout33 += g_0 * g_11 * g_24;
        gout34 += g_0 * g_10 * g_25;
        gout35 += g_0 * g_9 * g_26;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 1 * jstride, gout6);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout7);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout8);
    atomicAdd(peri + 3 * istride + 1 * jstride, gout9);
    atomicAdd(peri + 4 * istride + 1 * jstride, gout10);
    atomicAdd(peri + 5 * istride + 1 * jstride, gout11);
    atomicAdd(peri + 2 * jstride, gout12);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout13);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout14);
    atomicAdd(peri + 3 * istride + 2 * jstride, gout15);
    atomicAdd(peri + 4 * istride + 2 * jstride, gout16);
    atomicAdd(peri + 5 * istride + 2 * jstride, gout17);
    atomicAdd(peri + 3 * jstride, gout18);
    atomicAdd(peri + 1 * istride + 3 * jstride, gout19);
    atomicAdd(peri + 2 * istride + 3 * jstride, gout20);
    atomicAdd(peri + 3 * istride + 3 * jstride, gout21);
    atomicAdd(peri + 4 * istride + 3 * jstride, gout22);
    atomicAdd(peri + 5 * istride + 3 * jstride, gout23);
    atomicAdd(peri + 4 * jstride, gout24);
    atomicAdd(peri + 1 * istride + 4 * jstride, gout25);
    atomicAdd(peri + 2 * istride + 4 * jstride, gout26);
    atomicAdd(peri + 3 * istride + 4 * jstride, gout27);
    atomicAdd(peri + 4 * istride + 4 * jstride, gout28);
    atomicAdd(peri + 5 * istride + 4 * jstride, gout29);
    atomicAdd(peri + 5 * jstride, gout30);
    atomicAdd(peri + 1 * istride + 5 * jstride, gout31);
    atomicAdd(peri + 2 * istride + 5 * jstride, gout32);
    atomicAdd(peri + 3 * istride + 5 * jstride, gout33);
    atomicAdd(peri + 4 * istride + 5 * jstride, gout34);
    atomicAdd(peri + 5 * istride + 5 * jstride, gout35);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel2210(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x + xixj;
        double g_4 = c00x * (c00x + xixj) + b10;
        double g_5 = c00x * (2 * b10 + g_2) + xixj * g_2;
        double g_6 = xixj * (xixj + c00x) + xixj * c00x + c00x * c00x + b10;
        double g_7 = xixj * (xixj * c00x + c00x * c00x + b10) + xixj * g_2 +
                     c00x * g_2 + 2 * b10 * c00x;
        double g_8 = xixj * (xixj * g_2 + c00x * g_2 + 2 * b10 * c00x) +
                     xixj * (c00x * g_2 + 2 * b10 * c00x) +
                     c00x * (c00x * g_2 + 2 * b10 * c00x) + 3 * b10 * g_2;
        double g_9 = c0px;
        double g_10 = c0px * c00x + b00;
        double g_11 = b00 * c00x + b10 * c0px + c00x * g_10;
        double g_12 = c0px * (c00x + xixj) + b00;
        double g_13 = b00 * c00x + b10 * c0px + c00x * g_10 + xixj * g_10;
        double g_14 = 2 * b10 * g_10 + b00 * g_2 + c00x * g_11 + xixj * g_11;
        double g_15 = xixj * (xixj * c0px + c0px * c00x + b00) + xixj * g_10 +
                      c00x * g_10 + b10 * c0px + b00 * c00x;
        double g_16 =
            xixj * (xixj * g_10 + c00x * g_10 + b10 * c0px + b00 * c00x) +
            xixj * g_11 + c00x * g_11 + 2 * b10 * g_10 + b00 * g_2;
        double g_17 =
            xixj * (xixj * g_11 + c00x * g_11 + 2 * b10 * g_10 + b00 * g_2) +
            xixj * (c00x * g_11 + 2 * b10 * g_10 + b00 * g_2) +
            c00x * (c00x * g_11 + 2 * b10 * g_10 + b00 * g_2) +
            3 * b10 * g_11 + b00 * (c00x * g_2 + 2 * b10 * c00x);
        double g_18 = 1;
        double g_19 = c00y;
        double g_20 = c00y * c00y + b10;
        double g_21 = c00y + yiyj;
        double g_22 = c00y * (c00y + yiyj) + b10;
        double g_23 = c00y * (2 * b10 + g_20) + yiyj * g_20;
        double g_24 = yiyj * (yiyj + c00y) + yiyj * c00y + c00y * c00y + b10;
        double g_25 = yiyj * (yiyj * c00y + c00y * c00y + b10) + yiyj * g_20 +
                      c00y * g_20 + 2 * b10 * c00y;
        double g_26 = yiyj * (yiyj * g_20 + c00y * g_20 + 2 * b10 * c00y) +
                      yiyj * (c00y * g_20 + 2 * b10 * c00y) +
                      c00y * (c00y * g_20 + 2 * b10 * c00y) + 3 * b10 * g_20;
        double g_27 = c0py;
        double g_28 = c0py * c00y + b00;
        double g_29 = b00 * c00y + b10 * c0py + c00y * g_28;
        double g_30 = c0py * (c00y + yiyj) + b00;
        double g_31 = b00 * c00y + b10 * c0py + c00y * g_28 + yiyj * g_28;
        double g_32 = 2 * b10 * g_28 + b00 * g_20 + c00y * g_29 + yiyj * g_29;
        double g_33 = yiyj * (yiyj * c0py + c0py * c00y + b00) + yiyj * g_28 +
                      c00y * g_28 + b10 * c0py + b00 * c00y;
        double g_34 =
            yiyj * (yiyj * g_28 + c00y * g_28 + b10 * c0py + b00 * c00y) +
            yiyj * g_29 + c00y * g_29 + 2 * b10 * g_28 + b00 * g_20;
        double g_35 =
            yiyj * (yiyj * g_29 + c00y * g_29 + 2 * b10 * g_28 + b00 * g_20) +
            yiyj * (c00y * g_29 + 2 * b10 * g_28 + b00 * g_20) +
            c00y * (c00y * g_29 + 2 * b10 * g_28 + b00 * g_20) +
            3 * b10 * g_29 + b00 * (c00y * g_20 + 2 * b10 * c00y);
        double g_36 = weight0 * fac;
        double g_37 = c00z * g_36;
        double g_38 = b10 * g_36 + c00z * g_37;
        double g_39 = g_36 * (c00z + zizj);
        double g_40 = b10 * g_36 + c00z * g_37 + zizj * g_37;
        double g_41 = 2 * b10 * g_37 + c00z * g_38 + zizj * g_38;
        double g_42 = zizj * (zizj * g_36 + c00z * g_36) + zizj * g_37 +
                      c00z * g_37 + b10 * g_36;
        double g_43 = zizj * (zizj * g_37 + c00z * g_37 + b10 * g_36) +
                      zizj * g_38 + c00z * g_38 + 2 * b10 * g_37;
        double g_44 = zizj * (zizj * g_38 + c00z * g_38 + 2 * b10 * g_37) +
                      zizj * (c00z * g_38 + 2 * b10 * g_37) +
                      c00z * (c00z * g_38 + 2 * b10 * g_37) + 3 * b10 * g_38;
        double g_45 = c0pz * g_36;
        double g_46 = b00 * g_36 + c0pz * g_37;
        double g_47 = b00 * g_37 + b10 * g_45 + c00z * g_46;
        double g_48 = b00 * g_36 + c0pz * g_37 + zizj * g_45;
        double g_49 = b00 * g_37 + b10 * g_45 + c00z * g_46 + zizj * g_46;
        double g_50 = 2 * b10 * g_46 + b00 * g_38 + c00z * g_47 + zizj * g_47;
        double g_51 = zizj * (zizj * g_45 + c0pz * g_37 + b00 * g_36) +
                      zizj * g_46 + c00z * g_46 + b10 * g_45 + b00 * g_37;
        double g_52 =
            zizj * (zizj * g_46 + c00z * g_46 + b10 * g_45 + b00 * g_37) +
            zizj * g_47 + c00z * g_47 + 2 * b10 * g_46 + b00 * g_38;
        double g_53 =
            zizj * (zizj * g_47 + c00z * g_47 + 2 * b10 * g_46 + b00 * g_38) +
            zizj * (c00z * g_47 + 2 * b10 * g_46 + b00 * g_38) +
            c00z * (c00z * g_47 + 2 * b10 * g_46 + b00 * g_38) +
            3 * b10 * g_47 + b00 * (c00z * g_38 + 2 * b10 * g_37);
        gout0 += g_17 * g_18 * g_36;
        gout1 += g_16 * g_19 * g_36;
        gout2 += g_16 * g_18 * g_37;
        gout3 += g_15 * g_20 * g_36;
        gout4 += g_15 * g_19 * g_37;
        gout5 += g_15 * g_18 * g_38;
        gout6 += g_14 * g_21 * g_36;
        gout7 += g_13 * g_22 * g_36;
        gout8 += g_13 * g_21 * g_37;
        gout9 += g_12 * g_23 * g_36;
        gout10 += g_12 * g_22 * g_37;
        gout11 += g_12 * g_21 * g_38;
        gout12 += g_14 * g_18 * g_39;
        gout13 += g_13 * g_19 * g_39;
        gout14 += g_13 * g_18 * g_40;
        gout15 += g_12 * g_20 * g_39;
        gout16 += g_12 * g_19 * g_40;
        gout17 += g_12 * g_18 * g_41;
        gout18 += g_11 * g_24 * g_36;
        gout19 += g_10 * g_25 * g_36;
        gout20 += g_10 * g_24 * g_37;
        gout21 += g_9 * g_26 * g_36;
        gout22 += g_9 * g_25 * g_37;
        gout23 += g_9 * g_24 * g_38;
        gout24 += g_11 * g_21 * g_39;
        gout25 += g_10 * g_22 * g_39;
        gout26 += g_10 * g_21 * g_40;
        gout27 += g_9 * g_23 * g_39;
        gout28 += g_9 * g_22 * g_40;
        gout29 += g_9 * g_21 * g_41;
        gout30 += g_11 * g_18 * g_42;
        gout31 += g_10 * g_19 * g_42;
        gout32 += g_10 * g_18 * g_43;
        gout33 += g_9 * g_20 * g_42;
        gout34 += g_9 * g_19 * g_43;
        gout35 += g_9 * g_18 * g_44;
        gout36 += g_8 * g_27 * g_36;
        gout37 += g_7 * g_28 * g_36;
        gout38 += g_7 * g_27 * g_37;
        gout39 += g_6 * g_29 * g_36;
        gout40 += g_6 * g_28 * g_37;
        gout41 += g_6 * g_27 * g_38;
        gout42 += g_5 * g_30 * g_36;
        gout43 += g_4 * g_31 * g_36;
        gout44 += g_4 * g_30 * g_37;
        gout45 += g_3 * g_32 * g_36;
        gout46 += g_3 * g_31 * g_37;
        gout47 += g_3 * g_30 * g_38;
        gout48 += g_5 * g_27 * g_39;
        gout49 += g_4 * g_28 * g_39;
        gout50 += g_4 * g_27 * g_40;
        gout51 += g_3 * g_29 * g_39;
        gout52 += g_3 * g_28 * g_40;
        gout53 += g_3 * g_27 * g_41;
        gout54 += g_2 * g_33 * g_36;
        gout55 += g_1 * g_34 * g_36;
        gout56 += g_1 * g_33 * g_37;
        gout57 += g_0 * g_35 * g_36;
        gout58 += g_0 * g_34 * g_37;
        gout59 += g_0 * g_33 * g_38;
        gout60 += g_2 * g_30 * g_39;
        gout61 += g_1 * g_31 * g_39;
        gout62 += g_1 * g_30 * g_40;
        gout63 += g_0 * g_32 * g_39;
        gout64 += g_0 * g_31 * g_40;
        gout65 += g_0 * g_30 * g_41;
        gout66 += g_2 * g_27 * g_42;
        gout67 += g_1 * g_28 * g_42;
        gout68 += g_1 * g_27 * g_43;
        gout69 += g_0 * g_29 * g_42;
        gout70 += g_0 * g_28 * g_43;
        gout71 += g_0 * g_27 * g_44;
        gout72 += g_8 * g_18 * g_45;
        gout73 += g_7 * g_19 * g_45;
        gout74 += g_7 * g_18 * g_46;
        gout75 += g_6 * g_20 * g_45;
        gout76 += g_6 * g_19 * g_46;
        gout77 += g_6 * g_18 * g_47;
        gout78 += g_5 * g_21 * g_45;
        gout79 += g_4 * g_22 * g_45;
        gout80 += g_4 * g_21 * g_46;
        gout81 += g_3 * g_23 * g_45;
        gout82 += g_3 * g_22 * g_46;
        gout83 += g_3 * g_21 * g_47;
        gout84 += g_5 * g_18 * g_48;
        gout85 += g_4 * g_19 * g_48;
        gout86 += g_4 * g_18 * g_49;
        gout87 += g_3 * g_20 * g_48;
        gout88 += g_3 * g_19 * g_49;
        gout89 += g_3 * g_18 * g_50;
        gout90 += g_2 * g_24 * g_45;
        gout91 += g_1 * g_25 * g_45;
        gout92 += g_1 * g_24 * g_46;
        gout93 += g_0 * g_26 * g_45;
        gout94 += g_0 * g_25 * g_46;
        gout95 += g_0 * g_24 * g_47;
        gout96 += g_2 * g_21 * g_48;
        gout97 += g_1 * g_22 * g_48;
        gout98 += g_1 * g_21 * g_49;
        gout99 += g_0 * g_23 * g_48;
        gout100 += g_0 * g_22 * g_49;
        gout101 += g_0 * g_21 * g_50;
        gout102 += g_2 * g_18 * g_51;
        gout103 += g_1 * g_19 * g_51;
        gout104 += g_1 * g_18 * g_52;
        gout105 += g_0 * g_20 * g_51;
        gout106 += g_0 * g_19 * g_52;
        gout107 += g_0 * g_18 * g_53;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        gout81 = reduce(gout81);
        gout82 = reduce(gout82);
        gout83 = reduce(gout83);
        gout84 = reduce(gout84);
        gout85 = reduce(gout85);
        gout86 = reduce(gout86);
        gout87 = reduce(gout87);
        gout88 = reduce(gout88);
        gout89 = reduce(gout89);
        gout90 = reduce(gout90);
        gout91 = reduce(gout91);
        gout92 = reduce(gout92);
        gout93 = reduce(gout93);
        gout94 = reduce(gout94);
        gout95 = reduce(gout95);
        gout96 = reduce(gout96);
        gout97 = reduce(gout97);
        gout98 = reduce(gout98);
        gout99 = reduce(gout99);
        gout100 = reduce(gout100);
        gout101 = reduce(gout101);
        gout102 = reduce(gout102);
        gout103 = reduce(gout103);
        gout104 = reduce(gout104);
        gout105 = reduce(gout105);
        gout106 = reduce(gout106);
        gout107 = reduce(gout107);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 1 * jstride, gout6);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout7);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout8);
    atomicAdd(peri + 3 * istride + 1 * jstride, gout9);
    atomicAdd(peri + 4 * istride + 1 * jstride, gout10);
    atomicAdd(peri + 5 * istride + 1 * jstride, gout11);
    atomicAdd(peri + 2 * jstride, gout12);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout13);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout14);
    atomicAdd(peri + 3 * istride + 2 * jstride, gout15);
    atomicAdd(peri + 4 * istride + 2 * jstride, gout16);
    atomicAdd(peri + 5 * istride + 2 * jstride, gout17);
    atomicAdd(peri + 3 * jstride, gout18);
    atomicAdd(peri + 1 * istride + 3 * jstride, gout19);
    atomicAdd(peri + 2 * istride + 3 * jstride, gout20);
    atomicAdd(peri + 3 * istride + 3 * jstride, gout21);
    atomicAdd(peri + 4 * istride + 3 * jstride, gout22);
    atomicAdd(peri + 5 * istride + 3 * jstride, gout23);
    atomicAdd(peri + 4 * jstride, gout24);
    atomicAdd(peri + 1 * istride + 4 * jstride, gout25);
    atomicAdd(peri + 2 * istride + 4 * jstride, gout26);
    atomicAdd(peri + 3 * istride + 4 * jstride, gout27);
    atomicAdd(peri + 4 * istride + 4 * jstride, gout28);
    atomicAdd(peri + 5 * istride + 4 * jstride, gout29);
    atomicAdd(peri + 5 * jstride, gout30);
    atomicAdd(peri + 1 * istride + 5 * jstride, gout31);
    atomicAdd(peri + 2 * istride + 5 * jstride, gout32);
    atomicAdd(peri + 3 * istride + 5 * jstride, gout33);
    atomicAdd(peri + 4 * istride + 5 * jstride, gout34);
    atomicAdd(peri + 5 * istride + 5 * jstride, gout35);
    atomicAdd(peri + 1 * kstride, gout36);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout37);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout38);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout39);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout40);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout41);
    atomicAdd(peri + 1 * jstride + 1 * kstride, gout42);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * kstride, gout43);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * kstride, gout44);
    atomicAdd(peri + 3 * istride + 1 * jstride + 1 * kstride, gout45);
    atomicAdd(peri + 4 * istride + 1 * jstride + 1 * kstride, gout46);
    atomicAdd(peri + 5 * istride + 1 * jstride + 1 * kstride, gout47);
    atomicAdd(peri + 2 * jstride + 1 * kstride, gout48);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * kstride, gout49);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * kstride, gout50);
    atomicAdd(peri + 3 * istride + 2 * jstride + 1 * kstride, gout51);
    atomicAdd(peri + 4 * istride + 2 * jstride + 1 * kstride, gout52);
    atomicAdd(peri + 5 * istride + 2 * jstride + 1 * kstride, gout53);
    atomicAdd(peri + 3 * jstride + 1 * kstride, gout54);
    atomicAdd(peri + 1 * istride + 3 * jstride + 1 * kstride, gout55);
    atomicAdd(peri + 2 * istride + 3 * jstride + 1 * kstride, gout56);
    atomicAdd(peri + 3 * istride + 3 * jstride + 1 * kstride, gout57);
    atomicAdd(peri + 4 * istride + 3 * jstride + 1 * kstride, gout58);
    atomicAdd(peri + 5 * istride + 3 * jstride + 1 * kstride, gout59);
    atomicAdd(peri + 4 * jstride + 1 * kstride, gout60);
    atomicAdd(peri + 1 * istride + 4 * jstride + 1 * kstride, gout61);
    atomicAdd(peri + 2 * istride + 4 * jstride + 1 * kstride, gout62);
    atomicAdd(peri + 3 * istride + 4 * jstride + 1 * kstride, gout63);
    atomicAdd(peri + 4 * istride + 4 * jstride + 1 * kstride, gout64);
    atomicAdd(peri + 5 * istride + 4 * jstride + 1 * kstride, gout65);
    atomicAdd(peri + 5 * jstride + 1 * kstride, gout66);
    atomicAdd(peri + 1 * istride + 5 * jstride + 1 * kstride, gout67);
    atomicAdd(peri + 2 * istride + 5 * jstride + 1 * kstride, gout68);
    atomicAdd(peri + 3 * istride + 5 * jstride + 1 * kstride, gout69);
    atomicAdd(peri + 4 * istride + 5 * jstride + 1 * kstride, gout70);
    atomicAdd(peri + 5 * istride + 5 * jstride + 1 * kstride, gout71);
    atomicAdd(peri + 2 * kstride, gout72);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout73);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout74);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout75);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout76);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout77);
    atomicAdd(peri + 1 * jstride + 2 * kstride, gout78);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * kstride, gout79);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * kstride, gout80);
    atomicAdd(peri + 3 * istride + 1 * jstride + 2 * kstride, gout81);
    atomicAdd(peri + 4 * istride + 1 * jstride + 2 * kstride, gout82);
    atomicAdd(peri + 5 * istride + 1 * jstride + 2 * kstride, gout83);
    atomicAdd(peri + 2 * jstride + 2 * kstride, gout84);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * kstride, gout85);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * kstride, gout86);
    atomicAdd(peri + 3 * istride + 2 * jstride + 2 * kstride, gout87);
    atomicAdd(peri + 4 * istride + 2 * jstride + 2 * kstride, gout88);
    atomicAdd(peri + 5 * istride + 2 * jstride + 2 * kstride, gout89);
    atomicAdd(peri + 3 * jstride + 2 * kstride, gout90);
    atomicAdd(peri + 1 * istride + 3 * jstride + 2 * kstride, gout91);
    atomicAdd(peri + 2 * istride + 3 * jstride + 2 * kstride, gout92);
    atomicAdd(peri + 3 * istride + 3 * jstride + 2 * kstride, gout93);
    atomicAdd(peri + 4 * istride + 3 * jstride + 2 * kstride, gout94);
    atomicAdd(peri + 5 * istride + 3 * jstride + 2 * kstride, gout95);
    atomicAdd(peri + 4 * jstride + 2 * kstride, gout96);
    atomicAdd(peri + 1 * istride + 4 * jstride + 2 * kstride, gout97);
    atomicAdd(peri + 2 * istride + 4 * jstride + 2 * kstride, gout98);
    atomicAdd(peri + 3 * istride + 4 * jstride + 2 * kstride, gout99);
    atomicAdd(peri + 4 * istride + 4 * jstride + 2 * kstride, gout100);
    atomicAdd(peri + 5 * istride + 4 * jstride + 2 * kstride, gout101);
    atomicAdd(peri + 5 * jstride + 2 * kstride, gout102);
    atomicAdd(peri + 1 * istride + 5 * jstride + 2 * kstride, gout103);
    atomicAdd(peri + 2 * istride + 5 * jstride + 2 * kstride, gout104);
    atomicAdd(peri + 3 * istride + 5 * jstride + 2 * kstride, gout105);
    atomicAdd(peri + 4 * istride + 5 * jstride + 2 * kstride, gout106);
    atomicAdd(peri + 5 * istride + 5 * jstride + 2 * kstride, gout107);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel3010(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x * (2 * b10 + g_2);
        double g_4 = c0px;
        double g_5 = c0px * c00x + b00;
        double g_6 = b00 * c00x + b10 * c0px + c00x * g_5;
        double g_7 = 2 * b10 * g_5 + b00 * g_2 + c00x * g_6;
        double g_8 = 1;
        double g_9 = c00y;
        double g_10 = c00y * c00y + b10;
        double g_11 = c00y * (2 * b10 + g_10);
        double g_12 = c0py;
        double g_13 = c0py * c00y + b00;
        double g_14 = b00 * c00y + b10 * c0py + c00y * g_13;
        double g_15 = 2 * b10 * g_13 + b00 * g_10 + c00y * g_14;
        double g_16 = weight0 * fac;
        double g_17 = c00z * g_16;
        double g_18 = b10 * g_16 + c00z * g_17;
        double g_19 = 2 * b10 * g_17 + c00z * g_18;
        double g_20 = c0pz * g_16;
        double g_21 = b00 * g_16 + c0pz * g_17;
        double g_22 = b00 * g_17 + b10 * g_20 + c00z * g_21;
        double g_23 = 2 * b10 * g_21 + b00 * g_18 + c00z * g_22;
        gout0 += g_7 * g_8 * g_16;
        gout1 += g_6 * g_9 * g_16;
        gout2 += g_6 * g_8 * g_17;
        gout3 += g_5 * g_10 * g_16;
        gout4 += g_5 * g_9 * g_17;
        gout5 += g_5 * g_8 * g_18;
        gout6 += g_4 * g_11 * g_16;
        gout7 += g_4 * g_10 * g_17;
        gout8 += g_4 * g_9 * g_18;
        gout9 += g_4 * g_8 * g_19;
        gout10 += g_3 * g_12 * g_16;
        gout11 += g_2 * g_13 * g_16;
        gout12 += g_2 * g_12 * g_17;
        gout13 += g_1 * g_14 * g_16;
        gout14 += g_1 * g_13 * g_17;
        gout15 += g_1 * g_12 * g_18;
        gout16 += g_0 * g_15 * g_16;
        gout17 += g_0 * g_14 * g_17;
        gout18 += g_0 * g_13 * g_18;
        gout19 += g_0 * g_12 * g_19;
        gout20 += g_3 * g_8 * g_20;
        gout21 += g_2 * g_9 * g_20;
        gout22 += g_2 * g_8 * g_21;
        gout23 += g_1 * g_10 * g_20;
        gout24 += g_1 * g_9 * g_21;
        gout25 += g_1 * g_8 * g_22;
        gout26 += g_0 * g_11 * g_20;
        gout27 += g_0 * g_10 * g_21;
        gout28 += g_0 * g_9 * g_22;
        gout29 += g_0 * g_8 * g_23;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 6 * istride, gout6);
    atomicAdd(peri + 7 * istride, gout7);
    atomicAdd(peri + 8 * istride, gout8);
    atomicAdd(peri + 9 * istride, gout9);
    atomicAdd(peri + 1 * kstride, gout10);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout12);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout13);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout14);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout15);
    atomicAdd(peri + 6 * istride + 1 * kstride, gout16);
    atomicAdd(peri + 7 * istride + 1 * kstride, gout17);
    atomicAdd(peri + 8 * istride + 1 * kstride, gout18);
    atomicAdd(peri + 9 * istride + 1 * kstride, gout19);
    atomicAdd(peri + 2 * kstride, gout20);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout21);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout22);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout23);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout24);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout25);
    atomicAdd(peri + 6 * istride + 2 * kstride, gout26);
    atomicAdd(peri + 7 * istride + 2 * kstride, gout27);
    atomicAdd(peri + 8 * istride + 2 * kstride, gout28);
    atomicAdd(peri + 9 * istride + 2 * kstride, gout29);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel3011(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double xkxl = xk - bas_x[lsh];
    double ykyl = yk - bas_y[lsh];
    double zkzl = zk - bas_z[lsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x * (2 * b10 + g_2);
        double g_4 = c0px;
        double g_5 = c0px * c00x + b00;
        double g_6 = b00 * c00x + b10 * c0px + c00x * g_5;
        double g_7 = 2 * b10 * g_5 + b00 * g_2 + c00x * g_6;
        double g_8 = c0px + xkxl;
        double g_9 = c00x * (c0px + xkxl) + b00;
        double g_10 = b00 * c00x + b10 * c0px + c00x * g_5 + xkxl * g_2;
        double g_11 = 2 * b10 * g_5 + b00 * g_2 + c00x * g_6 + xkxl * g_3;
        double g_12 = c0px * (c0px + xkxl) + b01;
        double g_13 = b00 * c0px + b01 * c00x + c0px * g_5 + xkxl * g_5;
        double g_14 = xkxl * g_6 +
                      c00x * (c0px * g_5 + b01 * c00x + b00 * c0px) +
                      b10 * (c0px * c0px + b01) + 2 * b00 * g_5;
        double g_15 = xkxl * g_7 +
                      c00x * (c00x * (c0px * g_5 + b01 * c00x + b00 * c0px) +
                                 b10 * (c0px * c0px + b01) + 2 * b00 * g_5) +
                      2 * b10 * (c0px * g_5 + b01 * c00x + b00 * c0px) +
                      2 * b00 * g_6;
        double g_16 = 1;
        double g_17 = c00y;
        double g_18 = c00y * c00y + b10;
        double g_19 = c00y * (2 * b10 + g_18);
        double g_20 = c0py;
        double g_21 = c0py * c00y + b00;
        double g_22 = b00 * c00y + b10 * c0py + c00y * g_21;
        double g_23 = 2 * b10 * g_21 + b00 * g_18 + c00y * g_22;
        double g_24 = c0py + ykyl;
        double g_25 = c00y * (c0py + ykyl) + b00;
        double g_26 = b00 * c00y + b10 * c0py + c00y * g_21 + ykyl * g_18;
        double g_27 = 2 * b10 * g_21 + b00 * g_18 + c00y * g_22 + ykyl * g_19;
        double g_28 = c0py * (c0py + ykyl) + b01;
        double g_29 = b00 * c0py + b01 * c00y + c0py * g_21 + ykyl * g_21;
        double g_30 = ykyl * g_22 +
                      c00y * (c0py * g_21 + b01 * c00y + b00 * c0py) +
                      b10 * (c0py * c0py + b01) + 2 * b00 * g_21;
        double g_31 = ykyl * g_23 +
                      c00y * (c00y * (c0py * g_21 + b01 * c00y + b00 * c0py) +
                                 b10 * (c0py * c0py + b01) + 2 * b00 * g_21) +
                      2 * b10 * (c0py * g_21 + b01 * c00y + b00 * c0py) +
                      2 * b00 * g_22;
        double g_32 = weight0 * fac;
        double g_33 = c00z * g_32;
        double g_34 = b10 * g_32 + c00z * g_33;
        double g_35 = 2 * b10 * g_33 + c00z * g_34;
        double g_36 = c0pz * g_32;
        double g_37 = b00 * g_32 + c0pz * g_33;
        double g_38 = b00 * g_33 + b10 * g_36 + c00z * g_37;
        double g_39 = 2 * b10 * g_37 + b00 * g_34 + c00z * g_38;
        double g_40 = g_32 * (c0pz + zkzl);
        double g_41 = b00 * g_32 + c0pz * g_33 + zkzl * g_33;
        double g_42 = b00 * g_33 + b10 * g_36 + c00z * g_37 + zkzl * g_34;
        double g_43 = 2 * b10 * g_37 + b00 * g_34 + c00z * g_38 + zkzl * g_35;
        double g_44 = b01 * g_32 + c0pz * g_36 + zkzl * g_36;
        double g_45 = b00 * g_36 + b01 * g_33 + c0pz * g_37 + zkzl * g_37;
        double g_46 = zkzl * g_38 +
                      c00z * (c0pz * g_37 + b01 * g_33 + b00 * g_36) +
                      b10 * (c0pz * g_36 + b01 * g_32) + 2 * b00 * g_37;
        double g_47 =
            zkzl * g_39 +
            c00z * (c00z * (c0pz * g_37 + b01 * g_33 + b00 * g_36) +
                       b10 * (c0pz * g_36 + b01 * g_32) + 2 * b00 * g_37) +
            2 * b10 * (c0pz * g_37 + b01 * g_33 + b00 * g_36) + 2 * b00 * g_38;
        gout0 += g_15 * g_16 * g_32;
        gout1 += g_14 * g_17 * g_32;
        gout2 += g_14 * g_16 * g_33;
        gout3 += g_13 * g_18 * g_32;
        gout4 += g_13 * g_17 * g_33;
        gout5 += g_13 * g_16 * g_34;
        gout6 += g_12 * g_19 * g_32;
        gout7 += g_12 * g_18 * g_33;
        gout8 += g_12 * g_17 * g_34;
        gout9 += g_12 * g_16 * g_35;
        gout10 += g_11 * g_20 * g_32;
        gout11 += g_10 * g_21 * g_32;
        gout12 += g_10 * g_20 * g_33;
        gout13 += g_9 * g_22 * g_32;
        gout14 += g_9 * g_21 * g_33;
        gout15 += g_9 * g_20 * g_34;
        gout16 += g_8 * g_23 * g_32;
        gout17 += g_8 * g_22 * g_33;
        gout18 += g_8 * g_21 * g_34;
        gout19 += g_8 * g_20 * g_35;
        gout20 += g_11 * g_16 * g_36;
        gout21 += g_10 * g_17 * g_36;
        gout22 += g_10 * g_16 * g_37;
        gout23 += g_9 * g_18 * g_36;
        gout24 += g_9 * g_17 * g_37;
        gout25 += g_9 * g_16 * g_38;
        gout26 += g_8 * g_19 * g_36;
        gout27 += g_8 * g_18 * g_37;
        gout28 += g_8 * g_17 * g_38;
        gout29 += g_8 * g_16 * g_39;
        gout30 += g_7 * g_24 * g_32;
        gout31 += g_6 * g_25 * g_32;
        gout32 += g_6 * g_24 * g_33;
        gout33 += g_5 * g_26 * g_32;
        gout34 += g_5 * g_25 * g_33;
        gout35 += g_5 * g_24 * g_34;
        gout36 += g_4 * g_27 * g_32;
        gout37 += g_4 * g_26 * g_33;
        gout38 += g_4 * g_25 * g_34;
        gout39 += g_4 * g_24 * g_35;
        gout40 += g_3 * g_28 * g_32;
        gout41 += g_2 * g_29 * g_32;
        gout42 += g_2 * g_28 * g_33;
        gout43 += g_1 * g_30 * g_32;
        gout44 += g_1 * g_29 * g_33;
        gout45 += g_1 * g_28 * g_34;
        gout46 += g_0 * g_31 * g_32;
        gout47 += g_0 * g_30 * g_33;
        gout48 += g_0 * g_29 * g_34;
        gout49 += g_0 * g_28 * g_35;
        gout50 += g_3 * g_24 * g_36;
        gout51 += g_2 * g_25 * g_36;
        gout52 += g_2 * g_24 * g_37;
        gout53 += g_1 * g_26 * g_36;
        gout54 += g_1 * g_25 * g_37;
        gout55 += g_1 * g_24 * g_38;
        gout56 += g_0 * g_27 * g_36;
        gout57 += g_0 * g_26 * g_37;
        gout58 += g_0 * g_25 * g_38;
        gout59 += g_0 * g_24 * g_39;
        gout60 += g_7 * g_16 * g_40;
        gout61 += g_6 * g_17 * g_40;
        gout62 += g_6 * g_16 * g_41;
        gout63 += g_5 * g_18 * g_40;
        gout64 += g_5 * g_17 * g_41;
        gout65 += g_5 * g_16 * g_42;
        gout66 += g_4 * g_19 * g_40;
        gout67 += g_4 * g_18 * g_41;
        gout68 += g_4 * g_17 * g_42;
        gout69 += g_4 * g_16 * g_43;
        gout70 += g_3 * g_20 * g_40;
        gout71 += g_2 * g_21 * g_40;
        gout72 += g_2 * g_20 * g_41;
        gout73 += g_1 * g_22 * g_40;
        gout74 += g_1 * g_21 * g_41;
        gout75 += g_1 * g_20 * g_42;
        gout76 += g_0 * g_23 * g_40;
        gout77 += g_0 * g_22 * g_41;
        gout78 += g_0 * g_21 * g_42;
        gout79 += g_0 * g_20 * g_43;
        gout80 += g_3 * g_16 * g_44;
        gout81 += g_2 * g_17 * g_44;
        gout82 += g_2 * g_16 * g_45;
        gout83 += g_1 * g_18 * g_44;
        gout84 += g_1 * g_17 * g_45;
        gout85 += g_1 * g_16 * g_46;
        gout86 += g_0 * g_19 * g_44;
        gout87 += g_0 * g_18 * g_45;
        gout88 += g_0 * g_17 * g_46;
        gout89 += g_0 * g_16 * g_47;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        gout81 = reduce(gout81);
        gout82 = reduce(gout82);
        gout83 = reduce(gout83);
        gout84 = reduce(gout84);
        gout85 = reduce(gout85);
        gout86 = reduce(gout86);
        gout87 = reduce(gout87);
        gout88 = reduce(gout88);
        gout89 = reduce(gout89);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 6 * istride, gout6);
    atomicAdd(peri + 7 * istride, gout7);
    atomicAdd(peri + 8 * istride, gout8);
    atomicAdd(peri + 9 * istride, gout9);
    atomicAdd(peri + 1 * kstride, gout10);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout12);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout13);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout14);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout15);
    atomicAdd(peri + 6 * istride + 1 * kstride, gout16);
    atomicAdd(peri + 7 * istride + 1 * kstride, gout17);
    atomicAdd(peri + 8 * istride + 1 * kstride, gout18);
    atomicAdd(peri + 9 * istride + 1 * kstride, gout19);
    atomicAdd(peri + 2 * kstride, gout20);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout21);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout22);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout23);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout24);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout25);
    atomicAdd(peri + 6 * istride + 2 * kstride, gout26);
    atomicAdd(peri + 7 * istride + 2 * kstride, gout27);
    atomicAdd(peri + 8 * istride + 2 * kstride, gout28);
    atomicAdd(peri + 9 * istride + 2 * kstride, gout29);
    atomicAdd(peri + 1 * lstride, gout30);
    atomicAdd(peri + 1 * istride + 1 * lstride, gout31);
    atomicAdd(peri + 2 * istride + 1 * lstride, gout32);
    atomicAdd(peri + 3 * istride + 1 * lstride, gout33);
    atomicAdd(peri + 4 * istride + 1 * lstride, gout34);
    atomicAdd(peri + 5 * istride + 1 * lstride, gout35);
    atomicAdd(peri + 6 * istride + 1 * lstride, gout36);
    atomicAdd(peri + 7 * istride + 1 * lstride, gout37);
    atomicAdd(peri + 8 * istride + 1 * lstride, gout38);
    atomicAdd(peri + 9 * istride + 1 * lstride, gout39);
    atomicAdd(peri + 1 * kstride + 1 * lstride, gout40);
    atomicAdd(peri + 1 * istride + 1 * kstride + 1 * lstride, gout41);
    atomicAdd(peri + 2 * istride + 1 * kstride + 1 * lstride, gout42);
    atomicAdd(peri + 3 * istride + 1 * kstride + 1 * lstride, gout43);
    atomicAdd(peri + 4 * istride + 1 * kstride + 1 * lstride, gout44);
    atomicAdd(peri + 5 * istride + 1 * kstride + 1 * lstride, gout45);
    atomicAdd(peri + 6 * istride + 1 * kstride + 1 * lstride, gout46);
    atomicAdd(peri + 7 * istride + 1 * kstride + 1 * lstride, gout47);
    atomicAdd(peri + 8 * istride + 1 * kstride + 1 * lstride, gout48);
    atomicAdd(peri + 9 * istride + 1 * kstride + 1 * lstride, gout49);
    atomicAdd(peri + 2 * kstride + 1 * lstride, gout50);
    atomicAdd(peri + 1 * istride + 2 * kstride + 1 * lstride, gout51);
    atomicAdd(peri + 2 * istride + 2 * kstride + 1 * lstride, gout52);
    atomicAdd(peri + 3 * istride + 2 * kstride + 1 * lstride, gout53);
    atomicAdd(peri + 4 * istride + 2 * kstride + 1 * lstride, gout54);
    atomicAdd(peri + 5 * istride + 2 * kstride + 1 * lstride, gout55);
    atomicAdd(peri + 6 * istride + 2 * kstride + 1 * lstride, gout56);
    atomicAdd(peri + 7 * istride + 2 * kstride + 1 * lstride, gout57);
    atomicAdd(peri + 8 * istride + 2 * kstride + 1 * lstride, gout58);
    atomicAdd(peri + 9 * istride + 2 * kstride + 1 * lstride, gout59);
    atomicAdd(peri + 2 * lstride, gout60);
    atomicAdd(peri + 1 * istride + 2 * lstride, gout61);
    atomicAdd(peri + 2 * istride + 2 * lstride, gout62);
    atomicAdd(peri + 3 * istride + 2 * lstride, gout63);
    atomicAdd(peri + 4 * istride + 2 * lstride, gout64);
    atomicAdd(peri + 5 * istride + 2 * lstride, gout65);
    atomicAdd(peri + 6 * istride + 2 * lstride, gout66);
    atomicAdd(peri + 7 * istride + 2 * lstride, gout67);
    atomicAdd(peri + 8 * istride + 2 * lstride, gout68);
    atomicAdd(peri + 9 * istride + 2 * lstride, gout69);
    atomicAdd(peri + 1 * kstride + 2 * lstride, gout70);
    atomicAdd(peri + 1 * istride + 1 * kstride + 2 * lstride, gout71);
    atomicAdd(peri + 2 * istride + 1 * kstride + 2 * lstride, gout72);
    atomicAdd(peri + 3 * istride + 1 * kstride + 2 * lstride, gout73);
    atomicAdd(peri + 4 * istride + 1 * kstride + 2 * lstride, gout74);
    atomicAdd(peri + 5 * istride + 1 * kstride + 2 * lstride, gout75);
    atomicAdd(peri + 6 * istride + 1 * kstride + 2 * lstride, gout76);
    atomicAdd(peri + 7 * istride + 1 * kstride + 2 * lstride, gout77);
    atomicAdd(peri + 8 * istride + 1 * kstride + 2 * lstride, gout78);
    atomicAdd(peri + 9 * istride + 1 * kstride + 2 * lstride, gout79);
    atomicAdd(peri + 2 * kstride + 2 * lstride, gout80);
    atomicAdd(peri + 1 * istride + 2 * kstride + 2 * lstride, gout81);
    atomicAdd(peri + 2 * istride + 2 * kstride + 2 * lstride, gout82);
    atomicAdd(peri + 3 * istride + 2 * kstride + 2 * lstride, gout83);
    atomicAdd(peri + 4 * istride + 2 * kstride + 2 * lstride, gout84);
    atomicAdd(peri + 5 * istride + 2 * kstride + 2 * lstride, gout85);
    atomicAdd(peri + 6 * istride + 2 * kstride + 2 * lstride, gout86);
    atomicAdd(peri + 7 * istride + 2 * kstride + 2 * lstride, gout87);
    atomicAdd(peri + 8 * istride + 2 * kstride + 2 * lstride, gout88);
    atomicAdd(peri + 9 * istride + 2 * kstride + 2 * lstride, gout89);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel3020(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double b01 = b00 + tmp4 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x * (2 * b10 + g_2);
        double g_4 = c0px;
        double g_5 = c0px * c00x + b00;
        double g_6 = b00 * c00x + b10 * c0px + c00x * g_5;
        double g_7 = 2 * b10 * g_5 + b00 * g_2 + c00x * g_6;
        double g_8 = c0px * c0px + b01;
        double g_9 = b00 * c0px + b01 * c00x + c0px * g_5;
        double g_10 = 2 * b00 * g_5 + b10 * g_8 + c00x * g_9;
        double g_11 = 2 * (b00 * g_6 + b10 * g_9) + c00x * g_10;
        double g_12 = 1;
        double g_13 = c00y;
        double g_14 = c00y * c00y + b10;
        double g_15 = c00y * (2 * b10 + g_14);
        double g_16 = c0py;
        double g_17 = c0py * c00y + b00;
        double g_18 = b00 * c00y + b10 * c0py + c00y * g_17;
        double g_19 = 2 * b10 * g_17 + b00 * g_14 + c00y * g_18;
        double g_20 = c0py * c0py + b01;
        double g_21 = b00 * c0py + b01 * c00y + c0py * g_17;
        double g_22 = 2 * b00 * g_17 + b10 * g_20 + c00y * g_21;
        double g_23 = 2 * (b00 * g_18 + b10 * g_21) + c00y * g_22;
        double g_24 = weight0 * fac;
        double g_25 = c00z * g_24;
        double g_26 = b10 * g_24 + c00z * g_25;
        double g_27 = 2 * b10 * g_25 + c00z * g_26;
        double g_28 = c0pz * g_24;
        double g_29 = b00 * g_24 + c0pz * g_25;
        double g_30 = b00 * g_25 + b10 * g_28 + c00z * g_29;
        double g_31 = 2 * b10 * g_29 + b00 * g_26 + c00z * g_30;
        double g_32 = b01 * g_24 + c0pz * g_28;
        double g_33 = b00 * g_28 + b01 * g_25 + c0pz * g_29;
        double g_34 = 2 * b00 * g_29 + b10 * g_32 + c00z * g_33;
        double g_35 = 2 * (b00 * g_30 + b10 * g_33) + c00z * g_34;
        gout0 += g_11 * g_12 * g_24;
        gout1 += g_10 * g_13 * g_24;
        gout2 += g_10 * g_12 * g_25;
        gout3 += g_9 * g_14 * g_24;
        gout4 += g_9 * g_13 * g_25;
        gout5 += g_9 * g_12 * g_26;
        gout6 += g_8 * g_15 * g_24;
        gout7 += g_8 * g_14 * g_25;
        gout8 += g_8 * g_13 * g_26;
        gout9 += g_8 * g_12 * g_27;
        gout10 += g_7 * g_16 * g_24;
        gout11 += g_6 * g_17 * g_24;
        gout12 += g_6 * g_16 * g_25;
        gout13 += g_5 * g_18 * g_24;
        gout14 += g_5 * g_17 * g_25;
        gout15 += g_5 * g_16 * g_26;
        gout16 += g_4 * g_19 * g_24;
        gout17 += g_4 * g_18 * g_25;
        gout18 += g_4 * g_17 * g_26;
        gout19 += g_4 * g_16 * g_27;
        gout20 += g_7 * g_12 * g_28;
        gout21 += g_6 * g_13 * g_28;
        gout22 += g_6 * g_12 * g_29;
        gout23 += g_5 * g_14 * g_28;
        gout24 += g_5 * g_13 * g_29;
        gout25 += g_5 * g_12 * g_30;
        gout26 += g_4 * g_15 * g_28;
        gout27 += g_4 * g_14 * g_29;
        gout28 += g_4 * g_13 * g_30;
        gout29 += g_4 * g_12 * g_31;
        gout30 += g_3 * g_20 * g_24;
        gout31 += g_2 * g_21 * g_24;
        gout32 += g_2 * g_20 * g_25;
        gout33 += g_1 * g_22 * g_24;
        gout34 += g_1 * g_21 * g_25;
        gout35 += g_1 * g_20 * g_26;
        gout36 += g_0 * g_23 * g_24;
        gout37 += g_0 * g_22 * g_25;
        gout38 += g_0 * g_21 * g_26;
        gout39 += g_0 * g_20 * g_27;
        gout40 += g_3 * g_16 * g_28;
        gout41 += g_2 * g_17 * g_28;
        gout42 += g_2 * g_16 * g_29;
        gout43 += g_1 * g_18 * g_28;
        gout44 += g_1 * g_17 * g_29;
        gout45 += g_1 * g_16 * g_30;
        gout46 += g_0 * g_19 * g_28;
        gout47 += g_0 * g_18 * g_29;
        gout48 += g_0 * g_17 * g_30;
        gout49 += g_0 * g_16 * g_31;
        gout50 += g_3 * g_12 * g_32;
        gout51 += g_2 * g_13 * g_32;
        gout52 += g_2 * g_12 * g_33;
        gout53 += g_1 * g_14 * g_32;
        gout54 += g_1 * g_13 * g_33;
        gout55 += g_1 * g_12 * g_34;
        gout56 += g_0 * g_15 * g_32;
        gout57 += g_0 * g_14 * g_33;
        gout58 += g_0 * g_13 * g_34;
        gout59 += g_0 * g_12 * g_35;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 6 * istride, gout6);
    atomicAdd(peri + 7 * istride, gout7);
    atomicAdd(peri + 8 * istride, gout8);
    atomicAdd(peri + 9 * istride, gout9);
    atomicAdd(peri + 1 * kstride, gout10);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout11);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout12);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout13);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout14);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout15);
    atomicAdd(peri + 6 * istride + 1 * kstride, gout16);
    atomicAdd(peri + 7 * istride + 1 * kstride, gout17);
    atomicAdd(peri + 8 * istride + 1 * kstride, gout18);
    atomicAdd(peri + 9 * istride + 1 * kstride, gout19);
    atomicAdd(peri + 2 * kstride, gout20);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout21);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout22);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout23);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout24);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout25);
    atomicAdd(peri + 6 * istride + 2 * kstride, gout26);
    atomicAdd(peri + 7 * istride + 2 * kstride, gout27);
    atomicAdd(peri + 8 * istride + 2 * kstride, gout28);
    atomicAdd(peri + 9 * istride + 2 * kstride, gout29);
    atomicAdd(peri + 3 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 3 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 3 * kstride, gout32);
    atomicAdd(peri + 3 * istride + 3 * kstride, gout33);
    atomicAdd(peri + 4 * istride + 3 * kstride, gout34);
    atomicAdd(peri + 5 * istride + 3 * kstride, gout35);
    atomicAdd(peri + 6 * istride + 3 * kstride, gout36);
    atomicAdd(peri + 7 * istride + 3 * kstride, gout37);
    atomicAdd(peri + 8 * istride + 3 * kstride, gout38);
    atomicAdd(peri + 9 * istride + 3 * kstride, gout39);
    atomicAdd(peri + 4 * kstride, gout40);
    atomicAdd(peri + 1 * istride + 4 * kstride, gout41);
    atomicAdd(peri + 2 * istride + 4 * kstride, gout42);
    atomicAdd(peri + 3 * istride + 4 * kstride, gout43);
    atomicAdd(peri + 4 * istride + 4 * kstride, gout44);
    atomicAdd(peri + 5 * istride + 4 * kstride, gout45);
    atomicAdd(peri + 6 * istride + 4 * kstride, gout46);
    atomicAdd(peri + 7 * istride + 4 * kstride, gout47);
    atomicAdd(peri + 8 * istride + 4 * kstride, gout48);
    atomicAdd(peri + 9 * istride + 4 * kstride, gout49);
    atomicAdd(peri + 5 * kstride, gout50);
    atomicAdd(peri + 1 * istride + 5 * kstride, gout51);
    atomicAdd(peri + 2 * istride + 5 * kstride, gout52);
    atomicAdd(peri + 3 * istride + 5 * kstride, gout53);
    atomicAdd(peri + 4 * istride + 5 * kstride, gout54);
    atomicAdd(peri + 5 * istride + 5 * kstride, gout55);
    atomicAdd(peri + 6 * istride + 5 * kstride, gout56);
    atomicAdd(peri + 7 * istride + 5 * kstride, gout57);
    atomicAdd(peri + 8 * istride + 5 * kstride, gout58);
    atomicAdd(peri + 9 * istride + 5 * kstride, gout59);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel3100(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x * (2 * b10 + g_2);
        double g_4 = c00x + xixj;
        double g_5 = c00x * (c00x + xixj) + b10;
        double g_6 = c00x * (2 * b10 + g_2) + xixj * g_2;
        double g_7 = 3 * b10 * g_2 + c00x * g_3 + xixj * g_3;
        double g_8 = 1;
        double g_9 = c00y;
        double g_10 = c00y * c00y + b10;
        double g_11 = c00y * (2 * b10 + g_10);
        double g_12 = c00y + yiyj;
        double g_13 = c00y * (c00y + yiyj) + b10;
        double g_14 = c00y * (2 * b10 + g_10) + yiyj * g_10;
        double g_15 = 3 * b10 * g_10 + c00y * g_11 + yiyj * g_11;
        double g_16 = weight0 * fac;
        double g_17 = c00z * g_16;
        double g_18 = b10 * g_16 + c00z * g_17;
        double g_19 = 2 * b10 * g_17 + c00z * g_18;
        double g_20 = g_16 * (c00z + zizj);
        double g_21 = b10 * g_16 + c00z * g_17 + zizj * g_17;
        double g_22 = 2 * b10 * g_17 + c00z * g_18 + zizj * g_18;
        double g_23 = 3 * b10 * g_18 + c00z * g_19 + zizj * g_19;
        gout0 += g_7 * g_8 * g_16;
        gout1 += g_6 * g_9 * g_16;
        gout2 += g_6 * g_8 * g_17;
        gout3 += g_5 * g_10 * g_16;
        gout4 += g_5 * g_9 * g_17;
        gout5 += g_5 * g_8 * g_18;
        gout6 += g_4 * g_11 * g_16;
        gout7 += g_4 * g_10 * g_17;
        gout8 += g_4 * g_9 * g_18;
        gout9 += g_4 * g_8 * g_19;
        gout10 += g_3 * g_12 * g_16;
        gout11 += g_2 * g_13 * g_16;
        gout12 += g_2 * g_12 * g_17;
        gout13 += g_1 * g_14 * g_16;
        gout14 += g_1 * g_13 * g_17;
        gout15 += g_1 * g_12 * g_18;
        gout16 += g_0 * g_15 * g_16;
        gout17 += g_0 * g_14 * g_17;
        gout18 += g_0 * g_13 * g_18;
        gout19 += g_0 * g_12 * g_19;
        gout20 += g_3 * g_8 * g_20;
        gout21 += g_2 * g_9 * g_20;
        gout22 += g_2 * g_8 * g_21;
        gout23 += g_1 * g_10 * g_20;
        gout24 += g_1 * g_9 * g_21;
        gout25 += g_1 * g_8 * g_22;
        gout26 += g_0 * g_11 * g_20;
        gout27 += g_0 * g_10 * g_21;
        gout28 += g_0 * g_9 * g_22;
        gout29 += g_0 * g_8 * g_23;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 6 * istride, gout6);
    atomicAdd(peri + 7 * istride, gout7);
    atomicAdd(peri + 8 * istride, gout8);
    atomicAdd(peri + 9 * istride, gout9);
    atomicAdd(peri + 1 * jstride, gout10);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout11);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout12);
    atomicAdd(peri + 3 * istride + 1 * jstride, gout13);
    atomicAdd(peri + 4 * istride + 1 * jstride, gout14);
    atomicAdd(peri + 5 * istride + 1 * jstride, gout15);
    atomicAdd(peri + 6 * istride + 1 * jstride, gout16);
    atomicAdd(peri + 7 * istride + 1 * jstride, gout17);
    atomicAdd(peri + 8 * istride + 1 * jstride, gout18);
    atomicAdd(peri + 9 * istride + 1 * jstride, gout19);
    atomicAdd(peri + 2 * jstride, gout20);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout21);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout22);
    atomicAdd(peri + 3 * istride + 2 * jstride, gout23);
    atomicAdd(peri + 4 * istride + 2 * jstride, gout24);
    atomicAdd(peri + 5 * istride + 2 * jstride, gout25);
    atomicAdd(peri + 6 * istride + 2 * jstride, gout26);
    atomicAdd(peri + 7 * istride + 2 * jstride, gout27);
    atomicAdd(peri + 8 * istride + 2 * jstride, gout28);
    atomicAdd(peri + 9 * istride + 2 * jstride, gout29);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel3110(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double tmp3 = tmp1 * aij;
        double c0px = xkl - xk + tmp3 * xijxkl;
        double c0py = ykl - yk + tmp3 * yijykl;
        double c0pz = zkl - zk + tmp3 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x * (2 * b10 + g_2);
        double g_4 = c00x + xixj;
        double g_5 = c00x * (c00x + xixj) + b10;
        double g_6 = c00x * (2 * b10 + g_2) + xixj * g_2;
        double g_7 = 3 * b10 * g_2 + c00x * g_3 + xixj * g_3;
        double g_8 = c0px;
        double g_9 = c0px * c00x + b00;
        double g_10 = b00 * c00x + b10 * c0px + c00x * g_9;
        double g_11 = 2 * b10 * g_9 + b00 * g_2 + c00x * g_10;
        double g_12 = c0px * (c00x + xixj) + b00;
        double g_13 = b00 * c00x + b10 * c0px + c00x * g_9 + xixj * g_9;
        double g_14 = 2 * b10 * g_9 + b00 * g_2 + c00x * g_10 + xixj * g_10;
        double g_15 = 3 * b10 * g_10 + b00 * g_3 + c00x * g_11 + xixj * g_11;
        double g_16 = 1;
        double g_17 = c00y;
        double g_18 = c00y * c00y + b10;
        double g_19 = c00y * (2 * b10 + g_18);
        double g_20 = c00y + yiyj;
        double g_21 = c00y * (c00y + yiyj) + b10;
        double g_22 = c00y * (2 * b10 + g_18) + yiyj * g_18;
        double g_23 = 3 * b10 * g_18 + c00y * g_19 + yiyj * g_19;
        double g_24 = c0py;
        double g_25 = c0py * c00y + b00;
        double g_26 = b00 * c00y + b10 * c0py + c00y * g_25;
        double g_27 = 2 * b10 * g_25 + b00 * g_18 + c00y * g_26;
        double g_28 = c0py * (c00y + yiyj) + b00;
        double g_29 = b00 * c00y + b10 * c0py + c00y * g_25 + yiyj * g_25;
        double g_30 = 2 * b10 * g_25 + b00 * g_18 + c00y * g_26 + yiyj * g_26;
        double g_31 = 3 * b10 * g_26 + b00 * g_19 + c00y * g_27 + yiyj * g_27;
        double g_32 = weight0 * fac;
        double g_33 = c00z * g_32;
        double g_34 = b10 * g_32 + c00z * g_33;
        double g_35 = 2 * b10 * g_33 + c00z * g_34;
        double g_36 = g_32 * (c00z + zizj);
        double g_37 = b10 * g_32 + c00z * g_33 + zizj * g_33;
        double g_38 = 2 * b10 * g_33 + c00z * g_34 + zizj * g_34;
        double g_39 = 3 * b10 * g_34 + c00z * g_35 + zizj * g_35;
        double g_40 = c0pz * g_32;
        double g_41 = b00 * g_32 + c0pz * g_33;
        double g_42 = b00 * g_33 + b10 * g_40 + c00z * g_41;
        double g_43 = 2 * b10 * g_41 + b00 * g_34 + c00z * g_42;
        double g_44 = b00 * g_32 + c0pz * g_33 + zizj * g_40;
        double g_45 = b00 * g_33 + b10 * g_40 + c00z * g_41 + zizj * g_41;
        double g_46 = 2 * b10 * g_41 + b00 * g_34 + c00z * g_42 + zizj * g_42;
        double g_47 = 3 * b10 * g_42 + b00 * g_35 + c00z * g_43 + zizj * g_43;
        gout0 += g_15 * g_16 * g_32;
        gout1 += g_14 * g_17 * g_32;
        gout2 += g_14 * g_16 * g_33;
        gout3 += g_13 * g_18 * g_32;
        gout4 += g_13 * g_17 * g_33;
        gout5 += g_13 * g_16 * g_34;
        gout6 += g_12 * g_19 * g_32;
        gout7 += g_12 * g_18 * g_33;
        gout8 += g_12 * g_17 * g_34;
        gout9 += g_12 * g_16 * g_35;
        gout10 += g_11 * g_20 * g_32;
        gout11 += g_10 * g_21 * g_32;
        gout12 += g_10 * g_20 * g_33;
        gout13 += g_9 * g_22 * g_32;
        gout14 += g_9 * g_21 * g_33;
        gout15 += g_9 * g_20 * g_34;
        gout16 += g_8 * g_23 * g_32;
        gout17 += g_8 * g_22 * g_33;
        gout18 += g_8 * g_21 * g_34;
        gout19 += g_8 * g_20 * g_35;
        gout20 += g_11 * g_16 * g_36;
        gout21 += g_10 * g_17 * g_36;
        gout22 += g_10 * g_16 * g_37;
        gout23 += g_9 * g_18 * g_36;
        gout24 += g_9 * g_17 * g_37;
        gout25 += g_9 * g_16 * g_38;
        gout26 += g_8 * g_19 * g_36;
        gout27 += g_8 * g_18 * g_37;
        gout28 += g_8 * g_17 * g_38;
        gout29 += g_8 * g_16 * g_39;
        gout30 += g_7 * g_24 * g_32;
        gout31 += g_6 * g_25 * g_32;
        gout32 += g_6 * g_24 * g_33;
        gout33 += g_5 * g_26 * g_32;
        gout34 += g_5 * g_25 * g_33;
        gout35 += g_5 * g_24 * g_34;
        gout36 += g_4 * g_27 * g_32;
        gout37 += g_4 * g_26 * g_33;
        gout38 += g_4 * g_25 * g_34;
        gout39 += g_4 * g_24 * g_35;
        gout40 += g_3 * g_28 * g_32;
        gout41 += g_2 * g_29 * g_32;
        gout42 += g_2 * g_28 * g_33;
        gout43 += g_1 * g_30 * g_32;
        gout44 += g_1 * g_29 * g_33;
        gout45 += g_1 * g_28 * g_34;
        gout46 += g_0 * g_31 * g_32;
        gout47 += g_0 * g_30 * g_33;
        gout48 += g_0 * g_29 * g_34;
        gout49 += g_0 * g_28 * g_35;
        gout50 += g_3 * g_24 * g_36;
        gout51 += g_2 * g_25 * g_36;
        gout52 += g_2 * g_24 * g_37;
        gout53 += g_1 * g_26 * g_36;
        gout54 += g_1 * g_25 * g_37;
        gout55 += g_1 * g_24 * g_38;
        gout56 += g_0 * g_27 * g_36;
        gout57 += g_0 * g_26 * g_37;
        gout58 += g_0 * g_25 * g_38;
        gout59 += g_0 * g_24 * g_39;
        gout60 += g_7 * g_16 * g_40;
        gout61 += g_6 * g_17 * g_40;
        gout62 += g_6 * g_16 * g_41;
        gout63 += g_5 * g_18 * g_40;
        gout64 += g_5 * g_17 * g_41;
        gout65 += g_5 * g_16 * g_42;
        gout66 += g_4 * g_19 * g_40;
        gout67 += g_4 * g_18 * g_41;
        gout68 += g_4 * g_17 * g_42;
        gout69 += g_4 * g_16 * g_43;
        gout70 += g_3 * g_20 * g_40;
        gout71 += g_2 * g_21 * g_40;
        gout72 += g_2 * g_20 * g_41;
        gout73 += g_1 * g_22 * g_40;
        gout74 += g_1 * g_21 * g_41;
        gout75 += g_1 * g_20 * g_42;
        gout76 += g_0 * g_23 * g_40;
        gout77 += g_0 * g_22 * g_41;
        gout78 += g_0 * g_21 * g_42;
        gout79 += g_0 * g_20 * g_43;
        gout80 += g_3 * g_16 * g_44;
        gout81 += g_2 * g_17 * g_44;
        gout82 += g_2 * g_16 * g_45;
        gout83 += g_1 * g_18 * g_44;
        gout84 += g_1 * g_17 * g_45;
        gout85 += g_1 * g_16 * g_46;
        gout86 += g_0 * g_19 * g_44;
        gout87 += g_0 * g_18 * g_45;
        gout88 += g_0 * g_17 * g_46;
        gout89 += g_0 * g_16 * g_47;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        gout60 = reduce(gout60);
        gout61 = reduce(gout61);
        gout62 = reduce(gout62);
        gout63 = reduce(gout63);
        gout64 = reduce(gout64);
        gout65 = reduce(gout65);
        gout66 = reduce(gout66);
        gout67 = reduce(gout67);
        gout68 = reduce(gout68);
        gout69 = reduce(gout69);
        gout70 = reduce(gout70);
        gout71 = reduce(gout71);
        gout72 = reduce(gout72);
        gout73 = reduce(gout73);
        gout74 = reduce(gout74);
        gout75 = reduce(gout75);
        gout76 = reduce(gout76);
        gout77 = reduce(gout77);
        gout78 = reduce(gout78);
        gout79 = reduce(gout79);
        gout80 = reduce(gout80);
        gout81 = reduce(gout81);
        gout82 = reduce(gout82);
        gout83 = reduce(gout83);
        gout84 = reduce(gout84);
        gout85 = reduce(gout85);
        gout86 = reduce(gout86);
        gout87 = reduce(gout87);
        gout88 = reduce(gout88);
        gout89 = reduce(gout89);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 6 * istride, gout6);
    atomicAdd(peri + 7 * istride, gout7);
    atomicAdd(peri + 8 * istride, gout8);
    atomicAdd(peri + 9 * istride, gout9);
    atomicAdd(peri + 1 * jstride, gout10);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout11);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout12);
    atomicAdd(peri + 3 * istride + 1 * jstride, gout13);
    atomicAdd(peri + 4 * istride + 1 * jstride, gout14);
    atomicAdd(peri + 5 * istride + 1 * jstride, gout15);
    atomicAdd(peri + 6 * istride + 1 * jstride, gout16);
    atomicAdd(peri + 7 * istride + 1 * jstride, gout17);
    atomicAdd(peri + 8 * istride + 1 * jstride, gout18);
    atomicAdd(peri + 9 * istride + 1 * jstride, gout19);
    atomicAdd(peri + 2 * jstride, gout20);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout21);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout22);
    atomicAdd(peri + 3 * istride + 2 * jstride, gout23);
    atomicAdd(peri + 4 * istride + 2 * jstride, gout24);
    atomicAdd(peri + 5 * istride + 2 * jstride, gout25);
    atomicAdd(peri + 6 * istride + 2 * jstride, gout26);
    atomicAdd(peri + 7 * istride + 2 * jstride, gout27);
    atomicAdd(peri + 8 * istride + 2 * jstride, gout28);
    atomicAdd(peri + 9 * istride + 2 * jstride, gout29);
    atomicAdd(peri + 1 * kstride, gout30);
    atomicAdd(peri + 1 * istride + 1 * kstride, gout31);
    atomicAdd(peri + 2 * istride + 1 * kstride, gout32);
    atomicAdd(peri + 3 * istride + 1 * kstride, gout33);
    atomicAdd(peri + 4 * istride + 1 * kstride, gout34);
    atomicAdd(peri + 5 * istride + 1 * kstride, gout35);
    atomicAdd(peri + 6 * istride + 1 * kstride, gout36);
    atomicAdd(peri + 7 * istride + 1 * kstride, gout37);
    atomicAdd(peri + 8 * istride + 1 * kstride, gout38);
    atomicAdd(peri + 9 * istride + 1 * kstride, gout39);
    atomicAdd(peri + 1 * jstride + 1 * kstride, gout40);
    atomicAdd(peri + 1 * istride + 1 * jstride + 1 * kstride, gout41);
    atomicAdd(peri + 2 * istride + 1 * jstride + 1 * kstride, gout42);
    atomicAdd(peri + 3 * istride + 1 * jstride + 1 * kstride, gout43);
    atomicAdd(peri + 4 * istride + 1 * jstride + 1 * kstride, gout44);
    atomicAdd(peri + 5 * istride + 1 * jstride + 1 * kstride, gout45);
    atomicAdd(peri + 6 * istride + 1 * jstride + 1 * kstride, gout46);
    atomicAdd(peri + 7 * istride + 1 * jstride + 1 * kstride, gout47);
    atomicAdd(peri + 8 * istride + 1 * jstride + 1 * kstride, gout48);
    atomicAdd(peri + 9 * istride + 1 * jstride + 1 * kstride, gout49);
    atomicAdd(peri + 2 * jstride + 1 * kstride, gout50);
    atomicAdd(peri + 1 * istride + 2 * jstride + 1 * kstride, gout51);
    atomicAdd(peri + 2 * istride + 2 * jstride + 1 * kstride, gout52);
    atomicAdd(peri + 3 * istride + 2 * jstride + 1 * kstride, gout53);
    atomicAdd(peri + 4 * istride + 2 * jstride + 1 * kstride, gout54);
    atomicAdd(peri + 5 * istride + 2 * jstride + 1 * kstride, gout55);
    atomicAdd(peri + 6 * istride + 2 * jstride + 1 * kstride, gout56);
    atomicAdd(peri + 7 * istride + 2 * jstride + 1 * kstride, gout57);
    atomicAdd(peri + 8 * istride + 2 * jstride + 1 * kstride, gout58);
    atomicAdd(peri + 9 * istride + 2 * jstride + 1 * kstride, gout59);
    atomicAdd(peri + 2 * kstride, gout60);
    atomicAdd(peri + 1 * istride + 2 * kstride, gout61);
    atomicAdd(peri + 2 * istride + 2 * kstride, gout62);
    atomicAdd(peri + 3 * istride + 2 * kstride, gout63);
    atomicAdd(peri + 4 * istride + 2 * kstride, gout64);
    atomicAdd(peri + 5 * istride + 2 * kstride, gout65);
    atomicAdd(peri + 6 * istride + 2 * kstride, gout66);
    atomicAdd(peri + 7 * istride + 2 * kstride, gout67);
    atomicAdd(peri + 8 * istride + 2 * kstride, gout68);
    atomicAdd(peri + 9 * istride + 2 * kstride, gout69);
    atomicAdd(peri + 1 * jstride + 2 * kstride, gout70);
    atomicAdd(peri + 1 * istride + 1 * jstride + 2 * kstride, gout71);
    atomicAdd(peri + 2 * istride + 1 * jstride + 2 * kstride, gout72);
    atomicAdd(peri + 3 * istride + 1 * jstride + 2 * kstride, gout73);
    atomicAdd(peri + 4 * istride + 1 * jstride + 2 * kstride, gout74);
    atomicAdd(peri + 5 * istride + 1 * jstride + 2 * kstride, gout75);
    atomicAdd(peri + 6 * istride + 1 * jstride + 2 * kstride, gout76);
    atomicAdd(peri + 7 * istride + 1 * jstride + 2 * kstride, gout77);
    atomicAdd(peri + 8 * istride + 1 * jstride + 2 * kstride, gout78);
    atomicAdd(peri + 9 * istride + 1 * jstride + 2 * kstride, gout79);
    atomicAdd(peri + 2 * jstride + 2 * kstride, gout80);
    atomicAdd(peri + 1 * istride + 2 * jstride + 2 * kstride, gout81);
    atomicAdd(peri + 2 * istride + 2 * jstride + 2 * kstride, gout82);
    atomicAdd(peri + 3 * istride + 2 * jstride + 2 * kstride, gout83);
    atomicAdd(peri + 4 * istride + 2 * jstride + 2 * kstride, gout84);
    atomicAdd(peri + 5 * istride + 2 * jstride + 2 * kstride, gout85);
    atomicAdd(peri + 6 * istride + 2 * jstride + 2 * kstride, gout86);
    atomicAdd(peri + 7 * istride + 2 * jstride + 2 * kstride, gout87);
    atomicAdd(peri + 8 * istride + 2 * jstride + 2 * kstride, gout88);
    atomicAdd(peri + 9 * istride + 2 * jstride + 2 * kstride, gout89);
}

template <bool T>
__global__ static void GINTfill_int2e_kernel3200(ERITensor eri,
    BasisProdOffsets offsets, GINTEnvVars envs, BasisProdCache bpcache) {
    int ntasks_ij = offsets.ntasks_ij;
    long ntasks = ntasks_ij * offsets.ntasks_kl;
    long task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int igroup = nprim_ij * nprim_kl;
    ntasks *= igroup;
    if (task_ij >= ntasks)
        return;
    int kl = task_ij % nprim_kl;
    task_ij /= nprim_kl;
    int ij = task_ij % nprim_ij;
    task_ij /= nprim_ij;
    int task_kl = task_ij / ntasks_ij;
    task_ij = task_ij % ntasks_ij;

    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    int *bas_pair2bra = bpcache.bas_pair2bra;
    int *bas_pair2ket = bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;
    double *__restrict__ a12 = bpcache.a12;
    double *__restrict__ e12 = bpcache.e12;
    double *__restrict__ x12 = bpcache.x12;
    double *__restrict__ y12 = bpcache.y12;
    double *__restrict__ z12 = bpcache.z12;
    int nbas = bpcache.nbas;
    double *__restrict__ bas_x = bpcache.bas_coords;
    double *__restrict__ bas_y = bas_x + nbas;
    double *__restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double xixj = xi - bas_x[jsh];
    double yiyj = yi - bas_y[jsh];
    double zizj = zi - bas_z[jsh];
    ij += prim_ij;
    kl += prim_kl;
    double aij = a12[ij];
    double eij = e12[ij];
    double xij = x12[ij];
    double yij = y12[ij];
    double zij = z12[ij];
    double akl = a12[kl];
    double ekl = e12[kl];
    double xkl = x12[kl];
    double ykl = y12[kl];
    double zkl = z12[kl];
    double xijxkl = xij - xkl;
    double yijykl = yij - ykl;
    double zijzkl = zij - zkl;
    double aijkl = aij + akl;
    double a1 = aij * akl;
    double a0 = a1 / aijkl;
    double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
    double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

    double rw[6];
    double root0, weight0;
    GINTrys_root<3>(x, rw);
    int irys;
    for (irys = 0; irys < 3; ++irys) {
        root0 = rw[irys];
        weight0 = rw[irys + 3];
        double u2 = a0 * root0;
        double tmp4 = .5 / (u2 * aijkl + a1);
        double b00 = u2 * tmp4;
        double tmp1 = 2 * b00;
        double tmp2 = tmp1 * akl;
        double b10 = b00 + tmp4 * akl;
        double c00x = xij - xi - tmp2 * xijxkl;
        double c00y = yij - yi - tmp2 * yijykl;
        double c00z = zij - zi - tmp2 * zijzkl;
        double g_0 = 1;
        double g_1 = c00x;
        double g_2 = c00x * c00x + b10;
        double g_3 = c00x * (2 * b10 + g_2);
        double g_4 = c00x + xixj;
        double g_5 = c00x * (c00x + xixj) + b10;
        double g_6 = c00x * (2 * b10 + g_2) + xixj * g_2;
        double g_7 = 3 * b10 * g_2 + c00x * g_3 + xixj * g_3;
        double g_8 = xixj * (xixj + c00x) + xixj * c00x + c00x * c00x + b10;
        double g_9 = xixj * (xixj * c00x + c00x * c00x + b10) + xixj * g_2 +
                     c00x * g_2 + 2 * b10 * c00x;
        double g_10 = xixj * (xixj * g_2 + c00x * g_2 + 2 * b10 * c00x) +
                      xixj * g_3 + c00x * g_3 + 3 * b10 * g_2;
        double g_11 = xixj * (xixj * g_3 + c00x * g_3 + 3 * b10 * g_2) +
                      xixj * (c00x * g_3 + 3 * b10 * g_2) +
                      c00x * (c00x * g_3 + 3 * b10 * g_2) + 4 * b10 * g_3;
        double g_12 = 1;
        double g_13 = c00y;
        double g_14 = c00y * c00y + b10;
        double g_15 = c00y * (2 * b10 + g_14);
        double g_16 = c00y + yiyj;
        double g_17 = c00y * (c00y + yiyj) + b10;
        double g_18 = c00y * (2 * b10 + g_14) + yiyj * g_14;
        double g_19 = 3 * b10 * g_14 + c00y * g_15 + yiyj * g_15;
        double g_20 = yiyj * (yiyj + c00y) + yiyj * c00y + c00y * c00y + b10;
        double g_21 = yiyj * (yiyj * c00y + c00y * c00y + b10) + yiyj * g_14 +
                      c00y * g_14 + 2 * b10 * c00y;
        double g_22 = yiyj * (yiyj * g_14 + c00y * g_14 + 2 * b10 * c00y) +
                      yiyj * g_15 + c00y * g_15 + 3 * b10 * g_14;
        double g_23 = yiyj * (yiyj * g_15 + c00y * g_15 + 3 * b10 * g_14) +
                      yiyj * (c00y * g_15 + 3 * b10 * g_14) +
                      c00y * (c00y * g_15 + 3 * b10 * g_14) + 4 * b10 * g_15;
        double g_24 = weight0 * fac;
        double g_25 = c00z * g_24;
        double g_26 = b10 * g_24 + c00z * g_25;
        double g_27 = 2 * b10 * g_25 + c00z * g_26;
        double g_28 = g_24 * (c00z + zizj);
        double g_29 = b10 * g_24 + c00z * g_25 + zizj * g_25;
        double g_30 = 2 * b10 * g_25 + c00z * g_26 + zizj * g_26;
        double g_31 = 3 * b10 * g_26 + c00z * g_27 + zizj * g_27;
        double g_32 = zizj * (zizj * g_24 + c00z * g_24) + zizj * g_25 +
                      c00z * g_25 + b10 * g_24;
        double g_33 = zizj * (zizj * g_25 + c00z * g_25 + b10 * g_24) +
                      zizj * g_26 + c00z * g_26 + 2 * b10 * g_25;
        double g_34 = zizj * (zizj * g_26 + c00z * g_26 + 2 * b10 * g_25) +
                      zizj * g_27 + c00z * g_27 + 3 * b10 * g_26;
        double g_35 = zizj * (zizj * g_27 + c00z * g_27 + 3 * b10 * g_26) +
                      zizj * (c00z * g_27 + 3 * b10 * g_26) +
                      c00z * (c00z * g_27 + 3 * b10 * g_26) + 4 * b10 * g_27;
        gout0 += g_11 * g_12 * g_24;
        gout1 += g_10 * g_13 * g_24;
        gout2 += g_10 * g_12 * g_25;
        gout3 += g_9 * g_14 * g_24;
        gout4 += g_9 * g_13 * g_25;
        gout5 += g_9 * g_12 * g_26;
        gout6 += g_8 * g_15 * g_24;
        gout7 += g_8 * g_14 * g_25;
        gout8 += g_8 * g_13 * g_26;
        gout9 += g_8 * g_12 * g_27;
        gout10 += g_7 * g_16 * g_24;
        gout11 += g_6 * g_17 * g_24;
        gout12 += g_6 * g_16 * g_25;
        gout13 += g_5 * g_18 * g_24;
        gout14 += g_5 * g_17 * g_25;
        gout15 += g_5 * g_16 * g_26;
        gout16 += g_4 * g_19 * g_24;
        gout17 += g_4 * g_18 * g_25;
        gout18 += g_4 * g_17 * g_26;
        gout19 += g_4 * g_16 * g_27;
        gout20 += g_7 * g_12 * g_28;
        gout21 += g_6 * g_13 * g_28;
        gout22 += g_6 * g_12 * g_29;
        gout23 += g_5 * g_14 * g_28;
        gout24 += g_5 * g_13 * g_29;
        gout25 += g_5 * g_12 * g_30;
        gout26 += g_4 * g_15 * g_28;
        gout27 += g_4 * g_14 * g_29;
        gout28 += g_4 * g_13 * g_30;
        gout29 += g_4 * g_12 * g_31;
        gout30 += g_3 * g_20 * g_24;
        gout31 += g_2 * g_21 * g_24;
        gout32 += g_2 * g_20 * g_25;
        gout33 += g_1 * g_22 * g_24;
        gout34 += g_1 * g_21 * g_25;
        gout35 += g_1 * g_20 * g_26;
        gout36 += g_0 * g_23 * g_24;
        gout37 += g_0 * g_22 * g_25;
        gout38 += g_0 * g_21 * g_26;
        gout39 += g_0 * g_20 * g_27;
        gout40 += g_3 * g_16 * g_28;
        gout41 += g_2 * g_17 * g_28;
        gout42 += g_2 * g_16 * g_29;
        gout43 += g_1 * g_18 * g_28;
        gout44 += g_1 * g_17 * g_29;
        gout45 += g_1 * g_16 * g_30;
        gout46 += g_0 * g_19 * g_28;
        gout47 += g_0 * g_18 * g_29;
        gout48 += g_0 * g_17 * g_30;
        gout49 += g_0 * g_16 * g_31;
        gout50 += g_3 * g_12 * g_32;
        gout51 += g_2 * g_13 * g_32;
        gout52 += g_2 * g_12 * g_33;
        gout53 += g_1 * g_14 * g_32;
        gout54 += g_1 * g_13 * g_33;
        gout55 += g_1 * g_12 * g_34;
        gout56 += g_0 * g_15 * g_32;
        gout57 += g_0 * g_14 * g_33;
        gout58 += g_0 * g_13 * g_34;
        gout59 += g_0 * g_12 * g_35;
    }

    size_t istride = eri.stride_i;
    size_t jstride = eri.stride_j;
    size_t kstride = eri.stride_k;
    size_t lstride = eri.stride_l;
    int *ao_loc = bpcache.ao_loc;
    int i0 = ao_loc[ish] - eri.ao_offsets_i;
    int j0 = ao_loc[jsh] - eri.ao_offsets_j;
    int k0 = ao_loc[ksh] - eri.ao_offsets_k;
    int l0 = ao_loc[lsh] - eri.ao_offsets_l;
    double *peri =
        eri.data + l0 * lstride + k0 * kstride + j0 * jstride + i0 * istride;
    if constexpr (T) {
        auto reduce = SegReduce<double>(igroup);
        gout0 = reduce(gout0);
        gout1 = reduce(gout1);
        gout2 = reduce(gout2);
        gout3 = reduce(gout3);
        gout4 = reduce(gout4);
        gout5 = reduce(gout5);
        gout6 = reduce(gout6);
        gout7 = reduce(gout7);
        gout8 = reduce(gout8);
        gout9 = reduce(gout9);
        gout10 = reduce(gout10);
        gout11 = reduce(gout11);
        gout12 = reduce(gout12);
        gout13 = reduce(gout13);
        gout14 = reduce(gout14);
        gout15 = reduce(gout15);
        gout16 = reduce(gout16);
        gout17 = reduce(gout17);
        gout18 = reduce(gout18);
        gout19 = reduce(gout19);
        gout20 = reduce(gout20);
        gout21 = reduce(gout21);
        gout22 = reduce(gout22);
        gout23 = reduce(gout23);
        gout24 = reduce(gout24);
        gout25 = reduce(gout25);
        gout26 = reduce(gout26);
        gout27 = reduce(gout27);
        gout28 = reduce(gout28);
        gout29 = reduce(gout29);
        gout30 = reduce(gout30);
        gout31 = reduce(gout31);
        gout32 = reduce(gout32);
        gout33 = reduce(gout33);
        gout34 = reduce(gout34);
        gout35 = reduce(gout35);
        gout36 = reduce(gout36);
        gout37 = reduce(gout37);
        gout38 = reduce(gout38);
        gout39 = reduce(gout39);
        gout40 = reduce(gout40);
        gout41 = reduce(gout41);
        gout42 = reduce(gout42);
        gout43 = reduce(gout43);
        gout44 = reduce(gout44);
        gout45 = reduce(gout45);
        gout46 = reduce(gout46);
        gout47 = reduce(gout47);
        gout48 = reduce(gout48);
        gout49 = reduce(gout49);
        gout50 = reduce(gout50);
        gout51 = reduce(gout51);
        gout52 = reduce(gout52);
        gout53 = reduce(gout53);
        gout54 = reduce(gout54);
        gout55 = reduce(gout55);
        gout56 = reduce(gout56);
        gout57 = reduce(gout57);
        gout58 = reduce(gout58);
        gout59 = reduce(gout59);
        if (!reduce.first)
            return;
    }
    atomicAdd(peri + 0 * istride, gout0);
    atomicAdd(peri + 1 * istride, gout1);
    atomicAdd(peri + 2 * istride, gout2);
    atomicAdd(peri + 3 * istride, gout3);
    atomicAdd(peri + 4 * istride, gout4);
    atomicAdd(peri + 5 * istride, gout5);
    atomicAdd(peri + 6 * istride, gout6);
    atomicAdd(peri + 7 * istride, gout7);
    atomicAdd(peri + 8 * istride, gout8);
    atomicAdd(peri + 9 * istride, gout9);
    atomicAdd(peri + 1 * jstride, gout10);
    atomicAdd(peri + 1 * istride + 1 * jstride, gout11);
    atomicAdd(peri + 2 * istride + 1 * jstride, gout12);
    atomicAdd(peri + 3 * istride + 1 * jstride, gout13);
    atomicAdd(peri + 4 * istride + 1 * jstride, gout14);
    atomicAdd(peri + 5 * istride + 1 * jstride, gout15);
    atomicAdd(peri + 6 * istride + 1 * jstride, gout16);
    atomicAdd(peri + 7 * istride + 1 * jstride, gout17);
    atomicAdd(peri + 8 * istride + 1 * jstride, gout18);
    atomicAdd(peri + 9 * istride + 1 * jstride, gout19);
    atomicAdd(peri + 2 * jstride, gout20);
    atomicAdd(peri + 1 * istride + 2 * jstride, gout21);
    atomicAdd(peri + 2 * istride + 2 * jstride, gout22);
    atomicAdd(peri + 3 * istride + 2 * jstride, gout23);
    atomicAdd(peri + 4 * istride + 2 * jstride, gout24);
    atomicAdd(peri + 5 * istride + 2 * jstride, gout25);
    atomicAdd(peri + 6 * istride + 2 * jstride, gout26);
    atomicAdd(peri + 7 * istride + 2 * jstride, gout27);
    atomicAdd(peri + 8 * istride + 2 * jstride, gout28);
    atomicAdd(peri + 9 * istride + 2 * jstride, gout29);
    atomicAdd(peri + 3 * jstride, gout30);
    atomicAdd(peri + 1 * istride + 3 * jstride, gout31);
    atomicAdd(peri + 2 * istride + 3 * jstride, gout32);
    atomicAdd(peri + 3 * istride + 3 * jstride, gout33);
    atomicAdd(peri + 4 * istride + 3 * jstride, gout34);
    atomicAdd(peri + 5 * istride + 3 * jstride, gout35);
    atomicAdd(peri + 6 * istride + 3 * jstride, gout36);
    atomicAdd(peri + 7 * istride + 3 * jstride, gout37);
    atomicAdd(peri + 8 * istride + 3 * jstride, gout38);
    atomicAdd(peri + 9 * istride + 3 * jstride, gout39);
    atomicAdd(peri + 4 * jstride, gout40);
    atomicAdd(peri + 1 * istride + 4 * jstride, gout41);
    atomicAdd(peri + 2 * istride + 4 * jstride, gout42);
    atomicAdd(peri + 3 * istride + 4 * jstride, gout43);
    atomicAdd(peri + 4 * istride + 4 * jstride, gout44);
    atomicAdd(peri + 5 * istride + 4 * jstride, gout45);
    atomicAdd(peri + 6 * istride + 4 * jstride, gout46);
    atomicAdd(peri + 7 * istride + 4 * jstride, gout47);
    atomicAdd(peri + 8 * istride + 4 * jstride, gout48);
    atomicAdd(peri + 9 * istride + 4 * jstride, gout49);
    atomicAdd(peri + 5 * jstride, gout50);
    atomicAdd(peri + 1 * istride + 5 * jstride, gout51);
    atomicAdd(peri + 2 * istride + 5 * jstride, gout52);
    atomicAdd(peri + 3 * istride + 5 * jstride, gout53);
    atomicAdd(peri + 4 * istride + 5 * jstride, gout54);
    atomicAdd(peri + 5 * istride + 5 * jstride, gout55);
    atomicAdd(peri + 6 * istride + 5 * jstride, gout56);
    atomicAdd(peri + 7 * istride + 5 * jstride, gout57);
    atomicAdd(peri + 8 * istride + 5 * jstride, gout58);
    atomicAdd(peri + 9 * istride + 5 * jstride, gout59);
}
